[java]代码库
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.BufferedInputStream;
public class FileWork{
public static void main(String[] args){
//File f = new File("d:"+File.separator+"FileWork.java");
File f = new File("d:"+File.separator+"Java_work");
if(f.isDirectory()){ //判断是否是文件的一个目录(文件夹)
System.out.println("路径是目录!");
String str[] = f.list();
for(int i=0;i<str.length;i++){
System.out.println(str[i]);
}
}else if(f.isFile()){ //判断是否是标准文件
int b = 0;
FileInputStream fis =null;
BufferedInputStream bis= null;
try{
fis = new FileInputStream(f);
bis = new BufferedInputStream(fis);
while((b=bis.read())!=-1){
System.out.print((char)b);
}
}catch(FileNotFoundException e){
e.printStackTrace();
}
catch(IOException e){
e.printStackTrace();
}finally{
try{
if(bis!=null){
bis.close();
}
}catch(IOException e){
e.printStackTrace();
}
}
}
}
}