---
title: "io 文件读取通用格式"
author: "polokang"
date: "2011-04-24T13:44:30Z"
tags: []
categories: ["编程语言"]
slug: "io"
draft: false
lastmod: "2011-04-24T13:44:30Z"
id: 1014121
url: "https://polokang.iteye.com/blog/1014121"
---

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