package Suchas; import java.io.*;public class FileIO { public FileIO(String str) { File f = new File("data.txt"); try { File file = new File("data.txt"); FileWriter fw = new FileWriter(file); BufferedWriter bw = new BufferedWriter(fw); bw.write(str); bw.close(); } catch (IOException e) { e.printStackTrace(); } } public static void main(String[] args) { String str = "12345abcdef@#%&*软件工程"; new File(str); } }
package Suchas; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class Filedemo { public Filedemo() { File f = new File("data.txt"); try { BufferedReader br = new BufferedReader(new FileReader(f)); String str = br.readLine(); System.out.println(str); br.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public static void main(String[] args) { new Filedemo(); } }