- 文件输出流的应用。
定义如下字符串:
String str = “12345abcdef@#%&*软件工程”;
编写程序将该字符串写入文件”data.txt”。 - 文件输入流的应用。
修改第1题中的程序,读文件”data.txt”,将读到的数据输出在控制台。 - 谈一谈本次实训的体会。
import java.io.*; public class IO { public static void main(String[] args) throws IOException{ String str="12345abcde@#%&*软件工程"; File file=new File("d:\\tset.txt"); file.createNewFile(); FileInputStream fr=new FileInputStream(file); FileOutputStream fw=new FileOutputStream(file); byte[]bw=str.getBytes(); fw.write(bw); byte[]br=str.getBytes(); fr.read(br); String str$=new String(br); System.out.println(str$); fr.close(); fw.close(); } }
转载于:https://www.cnblogs.com/ShijouTakane/p/11137145.html