📄 fileiodemo.java
字号:
//【代码7-3-7】
//FileIODemo.java
import java.io.*
class FileIODemo
{
//main方法
public static void main(String args[])
{
FileIODemo aFileIODemo = new FileIODemo();
}
//构造方法
public FileIODemo
{
try
{
//利用系统输入设备作为文件输入流
FileInputStream fin = new FileInputStream(System.in);
//创建输出文件input.txt
FileOutputStream fout =
new FileOutputStream( new File("input.txt"));
int nKeyIn;
for(int n=0;n<10;n++)
{
//从标准输入设备读取10个字符输入
nKeyIn = fin.read();
//向文件输出流中写出输入的字符
fout.write(data);
}
//关闭输出流
fout.close();
//创建文件输入流为文件input.txt
FileInputStream fin = new FileInputStream(new File("input.txt"));
//文件输出流为系统标准输出
FileOutputStream fout = new FileOutputStream(System.out);
while(fin.available()>0)
{
//从文件中读字符
data = fin.read();
//写出文件输出流
fout.write(data);
}
//关闭输入流
fin.close();
//关闭输出流
fout.close();
}
//捕获文件异常
catch(FileNotFoundException e)
{
e.printStackTrace();
}
//捕获输入输出异常
catch(IOException exp)
{
exp.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -