public static void main(String[] args) { // TODO 自动生成的方法存根 File file = new File("data.txt"); String s = "12345abcdef@#%&*软件工程"; try { FileWriter te = new FileWriter (file); BufferedWriter out = new BufferedWriter (te); out.write(s); out.close(); te.close();
} catch (Exception e) { e.printStackTrace(); } try { FileReader fr = new FileReader(file); BufferedReader in = new BufferedReader(fr); String len = in.readLine(); System.out.println("文件中的信息是:"+ len); in.close(); fr.close(); }catch (Exception e) { e.printStackTrace(); } }