---
title: "IO操作"
author: "ntwjf"
date: "2015-06-10T09:30:21Z"
tags: []
categories: ["编程语言"]
slug: "io"
draft: true
lastmod: "2015-06-10T09:31:53Z"
id: 2218408
url: "https://ntwjf.iteye.com/blog/2218408"
---

1、文件读取

```
	@Test
	public void testFileInputStream(){
		InputStream in = null;
		try {
			in = new FileInputStream("f:/a/hello.txt");
			int readCount = 0;
			byte[] buffer = new byte[1024];
			while((readCount = in.read(buffer, 0, 1024)) != -1){
				String str = new String(buffer,0,readCount);
				System.out.println(str);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally{
			if(in != null){
				try {
					in.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
```