本帖最后由 xuehuayous 于 2014-4-6 21:52 编辑
写的读取键盘录入然后写到硬盘文件,操作完成之后关闭了文件输入输出流,为什么不能把文件删除?操作中
操作结束
- package com.itheima;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class Test{
- public static void main(String[] args) {
-
- BufferedReader bufr = null;
- BufferedWriter bufw = null;
- try {
- bufr = new BufferedReader(new InputStreamReader(System.in));
- bufw = new BufferedWriter(new FileWriter("Demo.txt", true));
-
- String line;
- while((line=bufr.readLine())!=null) {
- bufw.write(line, 0, line.length());
- bufw.newLine();
- bufw.flush();
- }
- } catch (Exception e) {
- throw new RuntimeException("文件读取创建失败!");
- } finally {
- try {
- if(bufr!=null) {
- bufr.close();
- }
- } catch (IOException e) {
- System.out.println("读取流关闭失败!");
- }
- try {
- if(bufw!=null) {
- bufw.close();
- }
- } catch (IOException e) {
- System.out.println("输出流关闭失败!");
- }
- }
- }
- }
复制代码
|