ITeye博客

io 文件读取通用格式

polokang · 2011-04-24 13:44 · JAVA基础 · 编程语言 · Markdown

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();
    }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。