- public static void writerDate(String s)
- {
- FileWriter fw=null;
- try
- {
- fw=new FileWriter("demo.txt");//创建文件
- fw.write(s);//将数据写入流
- }
- catch (IOException e)
- {
- throw new RuntimeException("写入失败");
- }
- finally
- {
- if(fw!=null)
- try
- {
- fw.close();//将写入流的数据刷到指定文件内,并关闭流资源
- }
- catch (IOException e)
- {
- }
- }
- }
复制代码 |