java读取文件为string

//读取文件为string
String filePath = "G:\\test.txt";
  //????? "res/";
  String sInput = null;
  try {
     String encoding="GBK";
     File file=new File(filePath);
     if(file.isFile() && file.exists()){
     InputStreamReader read = new InputStreamReader(
     new FileInputStream(file),encoding);
     BufferedReader bufferedReader = new BufferedReader(read);
     String lineTxt = null;
     while((lineTxt = bufferedReader.readLine()) != null){
     System.out.println(lineTxt);
     sInput = sInput.;
     }
     sInput = lineTxt;
     read.close();
     }else{
     System.out.println("cant");
     }
     } catch (Exception e) {
     System.out.println("wrong");
     e.printStackTrace();
      }

你可能感兴趣的:(java)