怎么用java读取txt文件
1个回答
展开全部
File file1 =new File("D:\\2.txt");
BufferedReader br = new BufferedReader(new FileReader(file1));
StringBuilder result = new StringBuilder();
String s = null;
while((s = br.readLine())!=null){//使用readLine方法,一次读一行
result.append(System.lineSeparator()+s.trim());
}
s = result.toString();
System.out.println(s);
BufferedReader br = new BufferedReader(new FileReader(file1));
StringBuilder result = new StringBuilder();
String s = null;
while((s = br.readLine())!=null){//使用readLine方法,一次读一行
result.append(System.lineSeparator()+s.trim());
}
s = result.toString();
System.out.println(s);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询