读写文件内容
public class IOStreamDemo { public static void main(String[] args) { try { BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("C:\\file_out.txt")); BufferedReader bufferedReader = new BufferedReader(new FileReader("c:\\hb.log")); String tempStr; while((tempStr = bufferedReader.readLine()) != null){ System.out.println(tempStr); bufferedWriter.write(tempStr); } bufferedReader.close(); //数据先是放到缓冲区中的,然后再写入文件,因此一定要用flush()方法,否则在文件中没有数据显示 bufferedWriter.flush(); bufferedWriter.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
public class ReadOfficeDoc { /* * 不能直接获取doc文档中的数据,获取的全部是乱码 */ public static void main(String[] args) { FileInputStream fis; try { fis = new FileInputStream("c:\\HUAWEI统一WebUI接口说明书.doc"); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fis)); String str; while((str = bufferedReader.readLine()) != null){ System.out.println(str); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
回忆过去,珍惜现在,放眼未来