java读取文本文件中的内容

public class ReadPwd {


public static String readTxt(String filePath) {
String lineTxt = null;
 try {
   File file = new File(filePath);
   if(file.isFile() && file.exists()) {
     InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "utf-8");
     BufferedReader br = new BufferedReader(isr);
     
     while ((lineTxt = br.readLine()) != null) {
        lineTxt+=lineTxt;
     }
     br.close();
   } else {
     System.out.println("文件不存在!");
   }
 } catch (Exception e) {
   System.out.println("文件读取错误!");
 }
return lineTxt;
 }
 


}

猜你喜欢

转载自blog.csdn.net/fight_man8866/article/details/80775266