java io读取文本文件

java io读取文本文件

public class ReadSql {

 public static void readsql(String filePath) throws Exception{
  String encoding = "gbk";
  File file = new File(filePath);
  if(file.isFile()&&file.exists()){
   InputStreamReader reader = new InputStreamReader(new FileInputStream(file),encoding);
  BufferedReader bufferedReader = new BufferedReader(reader);
   String line = null;
   while ((line = bufferedReader.readLine())!=null) {    
     System.out.println(line.toString());           
   }
   reader.close();
  }
 }
 public static void main(String[] args) throws Exception {
  System.out.println("=================================================");
  ReadSql.readsql("c:/rr.txt"); 
  
  System.out.println("=================================================");
 }
}

你可能感兴趣的:(java io读取文本文件)