`
ntwjf
  • 浏览: 1737 次
  • 性别: Icon_minigender_1
  • 来自: 南京
文章分类
社区版块
存档分类
最新评论

IO操作

    博客分类:
  • java
 
阅读更多

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

 

分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

Global site tag (gtag.js) - Google Analytics