最近学习Java IO编程,写遍笔记
废话不多说上代码
public class IOTest{
public static void main(String[] args){
//创建源 注意这里ace.txt是提前在项目文件夹创建好的一个txt文本
File src = new File("ace.txt");
//创建流
InputStream is = null;
try{
is = new FileInputStream(src);
int temp;
while((temp = is.read()) != -1){
system.out.print((char)temp);//因为这个读取的是一个简单英文字母文本,所以需要强转下temp
}
}catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try{
if(is != null){
//释放资源
is.close();
}
}catch (IOException e) {
e.printStackTrace();
}
}
}
}