× ×
不写时默认为friendly
7. 写个程序,要求创建一个文件,写入从键盘输入的一串字符,然后再读该文件并将文件内容显示在屏幕上。(18分)
import java.io.*;
class MyFileIo{
public static void main(String args[]){
FileInputStream fin;
FileOutputStream fout;
char ch;
int data;
try{
fin = new FileInputStream(FileDescriptor.in);
fout = new FileOutputStream(“myfile1”);
System.out.println(“请输入一串字符以#结束:”);
while((ch = (char)fin.read()) != ‘#’)
Fout.write(ch);
fin.close();
fou.close();
System.out.print(“”);
fin = new FileInputStream(“myfile1”);
fout = new FileOutpurStream(FileDescriptor.out);
while(fin.available() > 0){
data = fin.read();
fou.write(data);
}
fin.close();
fout.close();
}catch(FileNotFoundException e){
System.out.println(“File not found!”);
}carch(IOException e){}
}
}