Java如何读取txt文件的内容

如题所述

第1个回答  2018-05-26
public class Myword {
    public static void main(String[] args) throws IOException {
        try {
            FileInputStream file = new FileInputStream("e:/myText.txt");
            BufferedInputStream Bfile = new BufferedInputStream(file);
            byte[] b = new byte[1024];
            String s = "";
            int bytesRead=0;  
            while((bytesRead=Bfile.read(b))!=-1){
                s+= new String(b,0,bytesRead);
            }
            System.out.println(s); 
            }
     }