62,634
社区成员




package testcalendar;
import java.io.File;
public class TestFileTree {
public static void main(String[] args) {
File f=new File("d:");
printFileTree(f,0);
}
static void printFileTree(File file, int level) {
// TODO Auto-generated method stub
for (int i=0;i<level;i++){
System.out.print("-");
}
System.out.println(file.getName());
if(file.isDirectory()){
File [] files=file.listFiles();
for (File temp:files){
printFileTree(temp, level+1);
}
}
}
}
package cn.bjsxt.test;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class TestReadFile {
public static void main(String[] args) {
FileReader reader=null;
try {
reader=new FileReader("d:/a.txt");
char c=(char)reader.read();
char c2=(char)reader.read();
System.out.println(""+c+c2);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
try {
if(reader!=null){
reader.close();
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}
}
就这里reader=new FileReader("d:/a.txt");如果换下面的文件夹就可以,根目录就不行