Java中使用BufferedReader的readLine()方法讀取文件內容


 

 

String filePath = "C:\\Users\\91911\\Desktop\\test.txt";//文件路徑

File file = new File(filePath);

BufferedReader reader = null;

try {

  reader = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));//獲取字符流

  String line;

  while((line = reader.readLine()) != null){

    System.out.println(line);//循環的到的數據

  }

}catch(Exception e){}

finally{

  if(reader != null){

    try{

      reader.close();

    }catch(Exception e1){

    }

  }

}

 

了解更多

https://blog.csdn.net/GuangRong1/article/details/88764539


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM