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