io 文件读取通用格式

public static void main(String[] args) throws IOException
    {
        InputStream is = new FileInputStream("D:\\workspace\\files\\test.txt");
        
        byte[] buff = new byte[1024];
        
        //length:以整数形式返回实际读取的字节数
        int length;
        
        while (-1 != (length = is.read(buff, 0, 1024)))
        {            
            String str = new String(buff, 0, length);
            System.out.println(str);
        }
        
        is.close();
    }
 

你可能感兴趣的:(JAVA基础)