6.12实训作业
1. 文件輸出流的應用。
定義如下字符串:
String str = “12345abcdef@#%&*軟件工程”;
編寫程序將該字符串寫入文件”data.txt”。
2. 文件輸入流的應用。
修改第1題中的程序,讀文件”data.txt”,將讀到的數據輸出在控制臺。
?
package bbb;
import java.io.*;
public class FileTest {
public static void main(String[]args){
File file=new File("data.txt");
String str="201801420131軟件工程江序林";
char str1[]=new char [1024];
try{
file.createNewFile();
FileWriter sc=new FileWriter(file);
sc.write(str);
sc.close();
}catch(IOException e){
e.printStackTrace();
}
try{
FileReader in=new FileReader(file);
int len=in.read(str1);
System.out.print(new String(str1,0,len));
}catch(FileNotFoundException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
}
}
轉載于:https://www.cnblogs.com/ghjd/p/11126851.html
總結
- 上一篇: 安卓逆向入门教程(一)
- 下一篇: 从零开始-小程序采坑记录