java中读text文件

import java.io.*;

public class Readfile {
    public void readfile() throws IOException{
        File f=new File("/var/www/html/study/test.txt");
        if(f.isFile() &&  f.exists()){
            InputStream file = new FileInputStream(f);
            InputStreamReader read = new InputStreamReader(file,"GBK");
            BufferedReader bufferedReader = new BufferedReader(read);
            String line = null;
            while((line=bufferedReader.readLine()) != null){

                System.out.print(line);
            }
        }else{
            System.out.print("this file is not exit");
        }

    }
}

猜你喜欢

转载自blog.csdn.net/margin_0px/article/details/81701304