java 怎么循环读取文件内容

如题所述

public class Test {

public  void  getRemoteId(String filePath){
BufferedReader br = null;
try{
//读取
String pathName = "D:\\1.txt";
br = new BufferedReader(new FileReader(new File(pathName)));
String line = "";
while((line = br.readLine()) != null){
    System.out.println(line);
}

}catch(Exception e){
 System.out.println("read file error"+e.getMessage());
}finally{
if(br != null)
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
        
    }
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-04-25
用while
还有有输入流,

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网