楼上的可以看作深度中的中序旦纤遍历
下面实现前序、后序、及广度方法
public static void dfsPreReadFiles(File folder){
System.out.println(folder.getAbsolutePath()) //do something with root
File[] fs=folder.listFiles()
if(fs!=null){
for(File tmpF:fs){ if(tmpF.isFile())
System.out.println(tmpF.getAbsolutePath())
else
dfsPreReadFiles(tmpF)
}
}
}
public static void dfsAftReadFiles(File folder){
File[] fs=folder.listFiles()
if(fs!=null){
for(File tmpF:fs){
if(tmpF.isFile())
System.out.println(tmpF.getAbsolutePath())
else
dfsAftReadFiles(tmpF)
}
}
System.out.println(folder.getAbsolutePath()) //do something with root
}
public static void bfsReadFiles(File folder){
Queue<File>fileq=new LinkedList<File>()
fileq.offer(folder)
File headerF
//获取对头元素
while((headerF=fileq.poll())!=null){
System.out.println(headerF.getAbsolutePath()) //do some with header File[] listFs=headerF.listFiles()
//把对头元素的儿子节点放入队尾
if(listFs!=null&&listFs.length>模贺仿0){
fileq.addAll(Arrays.asList(listFs))
}
}
}
不知道你是想做什么的,不过你的EOF很容易解释,你只写了一行,你却读了2次看这3行
b.writeUTF("SayString \"")
System.out.println(a.readUTF())
temp = (String)a.readUTF()
具虚数体要根据你自己的情况判断把哪一行给删除了
package test
import java.io.*
public class Test2 {
public static void main(String[] args) throws IOException {
// String temp = new String()
String temp = new String()
try {
FileInputStream in = new FileInputStream("d:\\a.txt")
DataInputStream a = new DataInputStream(in)
FileOutputStream out = new FileOutputStream("d:\\b.txt")
DataOutputStream b = new DataOutputStream(out)
do {
b.writeUTF("SayString \毕态"")
System.out.println(a.readUTF())
//temp = (String) a.readUTF()
// temp="wahaha"
b.writeUTF(temp)
b.writeUTF("\"")
b.writeUTF("\n")
b.writeUTF("KeyPress 13,1")
b.writeUTF("\n")
b.writeUTF("Delay 700")
b.writeUTF("\差数首n")
} while (temp == "end")
b.close()
a.close()
out.close()
in.close()
} catch (IOException e) {
System.out.println("ERROR")
}
}
}
in.readLine()的时候,实际只能接受一行。但羡银态是你写了两行。readLine()可兄源以用循环,下面代搏手码没测试。只给了思路。
..............................
int index=0
while(true){
if(index==0){
String x=in.readLine()
X = Integer.valueOf(x.trim())
}
if(index==1){
String y=in.readLine()
Y = Integer.valueOf(y.trim())
}
index++
if(index==2) break//跳出循环
}
.....................
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)