亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

逐行讀取文本文件

逐行讀取文本文件

白豬掌柜的 2022-10-26 16:52:53
我試過這種方式,但它沒有找到文本文件。try {    FileInputStream fstream = new FileInputStream("textfile.txt");    DataInputStream in = new DataInputStream(fstream);    BufferedReader br = new BufferedReader(new InputStreamReader(in));    String strLine;    // Read File Line By Line    while ((strLine = br.readLine()) != null) {        // Print the content on the console        System.out.println(strLine);    }    // Close the input stream    in.close();} catch (Exception e) {// Catch exception if any    System.err.println("Error: " + e.getMessage());}所有文件都在同一個包中。
查看完整描述

1 回答

?
喵喵時光機

TA貢獻1846條經驗 獲得超7個贊

您的文本文件位于“src”中的“trainer”包中,因此當您請求它時,您必須使用"src/trainer/textfile.txt". 前面/表示應用程序的根,例如,如果您不導出到可運行的 jar,則它是可選的。

FileInputStream fstream = new FileInputStream("src/trainer/textfile.txt");


查看完整回答
反對 回復 2022-10-26
  • 1 回答
  • 0 關注
  • 96 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號