在java中读取文本文件,然后编写新文件

时间:2013-11-18 21:23:36

标签: java text bufferedreader streamwriter bufferedwriter

我正在尝试将此代码上的printwriter格式化为仅打印小写并删除所有非字母字符。

干杯

import java.io.*;

public class TextFile {
public static void main (String[] args) throws IOException {
                File file1 = new File("PG.txt");
                File file2 = new File("newfile.txt"); 

                BufferedReader in = (new BufferedReader(new FileReader(file1)));
                PrintWriter out = (new PrintWriter(new FileWriter(file2)));

                int ch;
                while ((ch = in.read()) != -1){
                    out.write(ch);

                }
                in.close();
                out.close();
    }       
}

0 个答案:

没有答案