1 package work;
2
3 import java.io.BufferedWriter;
4 import java.io.File;
5 import java.io.FileWriter;
6 import java.io.IOException;
7
8 public class OutputData {
9 public OutputData(String str)
10 {
11 File f = new File("data.txt");
12 try {
13 BufferedWriter bw = new BufferedWriter(new FileWriter(f));
14 bw.write(str);
15 bw.close();
16 } catch (IOException e) {
17 // TODO 自动生成的 catch 块
18 e.printStackTrace();
19 }
20 }
21 public static void main(String[] args) {
22 String str = "12345abcdef@#%&*软件工程";
23 new OutputData(str);
24
25 }
26
27 }
1 package work;
2
3 import java.io.BufferedReader;
4 import java.io.File;
5 import java.io.FileNotFoundException;
6 import java.io.FileReader;
7 import java.io.IOException;
8
9 public class InputData {
10 public InputData()
11 {
12 File f = new File("data.txt");
13 try {
14 BufferedReader br = new BufferedReader(new FileReader(f));
15 String str = br.readLine();
16 System.out.println(str);
17 br.close();
18 } catch (FileNotFoundException e) {
19 // TODO 自动生成的 catch 块
20 e.printStackTrace();
21 } catch (IOException e) {
22 // TODO 自动生成的 catch 块
23 e.printStackTrace();
24 }
25
26
27 }
28 public static void main(String[] args) {
29 new InputData();
30
31 }
32
33 }