public class FileReadTest{
public static String readFile(String theFile){
String content = "";
try{
File read = new File(theFile);
BufferedReader br = new BufferedReader(new FileReader(read));
content = br.readLine();
System.out.println(theFile+ " 文件内容如下:\n"+content);
br.close();
}catch(FileNotFoundException e){ //文件未找到
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
return content;
}
public static void main(String[] args){
String cont="";
cont=readFile("E:/javaWP/crm_FilesName.txt");
}
}
java 代码读取指定文件
最新推荐文章于 2024-04-15 05:12:44 发布
import java.io.*;