1.输入输出流的应用
在程序中创建一个文本文件myfile.txt,从键盘输入一串字符,然后在读取改文件并将文本文件内容显示在屏幕上
package practice;
import java.io.*;
class shidianyi {
public static void main(String[] args) {
// TODO Auto-generated method stub
char ch;
int data;
try (
FileInputStream fin = new FileInputStream(FileDescriptor.in) ;
FileOutputStream fout = new FileOutputStream("D:/CGJ/MYFFILE.TXT");
){
System.out.println("请输入一串字符,并用#号结束:");
while((ch =(char)fin.read())!='#')
fout.write(ch);
}
catch(FileNotFoundException e) {
System.out.println("文件没找到");
}
catch(IOException e) {}
try(FileInputStream fin = new FileInputStream("D:/CGJ/MYFFILE.TXT");
FileOutputStream fout = new FileOutputStream(FileDescriptor.out);
){
while(fin.available()>0) {
data = fin.read();
fout.write(data);
}
}
catch(IOException e) {}
}
}
用FileInputSt