IO读取数据标准步骤

让人想犯罪 __ 提交于 2020-03-17 13:50:36
package cn.text.one;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author pc
 *操作步骤   1.创建源 2.选择流  3.操作 4.释放资源
 */
public class Text01 {
	public static void main(String[] args) {
		InputStream in=null;
		File file=new File("src\\cn\\text\\one\\abc.txt");
		try {
			in=new FileInputStream(file);
			int temp;
			while((temp=in.read())!=-1) {
                System.out.print((char)temp+",");
			}
			//释放资源
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				if(null!=in) {
					in.close();
				}
				
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		}
		}
	

在这里插入图片描述

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!