JAVA 读取本地文本文件


 String encoding = "GBK";
File file = new File("D:\\jz_activity_exchange_voucher-INSERT.txt");
if (file.isFile() && file.exists()) { //判断文件是否存在
InputStreamReader read = new InputStreamReader(
new FileInputStream(file), encoding);//考虑到编码格式
BufferedReader bufferedReader = new BufferedReader(read);
String lineTxt = null;
while ((lineTxt = bufferedReader.readLine()) != null) {
System.out.println(lineTxt);
}
 read.close();
} else {
System.out.println("找不到指定的文件");
return new Success<>(false);
}
} catch (Exception e) {
System.out.println("读取文件内容出错");
e.printStackTrace();
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM