本文实例为大家分享了java读取txt文件的具体代码,供大家参考,具体内容如下学习小记: 1、首先要根据路径获取你的 txt 文本文件。File file = new File(path); 2、将获取到的这个字节码流读进缓存。new
本文实例为大家分享了java读取txt文件的具体代码,供大家参考,具体内容如下
学习小记:
1、首先要根据路径获取你的 txt 文本文件。File file = new File(path);
2、将获取到的这个字节码流读进缓存。new FileInputStream(file) ;
3、然后对刚才读进缓存的输入流进行解读,生成对应字节流。InputStreamReader(readIn)
4、再然后通过 BufferedReader 这个类进行一行一行的输出。bufferedReader.readLine()
代码:
public static void ReadTxt () { try { File file = new File("E:\\text.txt"); FileInputStream readIn = new FileInputStream(file); InputStreamReader read = new InputStreamReader(readIn, "utf-8"); BufferedReader bufferedReader = new BufferedReader(read); String oneLine= null; while((oneLine= bufferedReader.readLine()) != null){ System.out.println(lineTxt); } read.close(); } catch (Exception e) { System.out.println("读取文件内容出错"); e.printStackTrace(); }}
--结束END--
本文标题: java读取txt文件代码片段
本文链接: https://www.lsjlt.com/news/226532.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-05
2024-05-05
2024-05-05
2024-05-05
2024-05-05
2024-05-05
2024-05-05
2024-05-05
2024-05-05
2024-05-05
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0