如题所述
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();
}
}
}
}
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
还有有输入流,
还有有输入流,