6.12实训作业
1. 文件輸出流的應(yīng)用。
定義如下字符串:
String str = “12345abcdef@#%&*軟件工程”;
編寫程序?qū)⒃撟址畬懭胛募眃ata.txt”。
2. 文件輸入流的應(yīng)用。
修改第1題中的程序,讀文件”data.txt”,將讀到的數(shù)據(jù)輸出在控制臺(tái)。
?
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();
}
}
}
轉(zhuǎn)載于:https://www.cnblogs.com/ghjd/p/11126851.html
總結(jié)
- 上一篇: 安卓逆向入门教程(一)
- 下一篇: 从零开始-小程序采坑记录