java中如何读文件..具体怎么运行这个文件?
//=============================读文件
package fier;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
public class Sdsd {
/**
* @param args
*/
public static void main(String[] args) {
read("E:\\123.txt");
}
public static void read(String file) {
String s = null;
StringBuffer sb = new StringBuffer();
File f = new File(file);
if (f.exists()) {
System.out.println("文件存在");
try {
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(f)));
while ((s = br.readLine()) != null) {
sb.append(s);
}
System.out.println(sb);
} catch (Exception e) {
e.printStackTrace();
}
}else{
System.out.println("文件不存在!");
}
}
}