欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java处理文本文件中的乱码字符,java文本文件,package com.

来源: javaer 分享于  点击 46535 次 点评:233

java处理文本文件中的乱码字符,java文本文件,package com.


package com.yonyou.jekey;import java.io.BufferedReader;import java.io.File;import java.io.FileOutputStream;import java.io.FileReader;import java.io.IOException;import java.io.PrintWriter;/* *  */public class Replacelm {    public static BufferedReader bufread;    /**     * @param args     * @throws IOException     */    public static void main(String[] args) throws IOException {        // TODO Auto-generated method stub        String input = args[0];        String output = args[1];        File outputf = creatTxtFile(output);        String read, write;        String regex = "[^\\p{Graph}\\s]";        FileReader fileread;        fileread = new FileReader(input);        bufread = new BufferedReader(fileread);        FileOutputStream fos = new FileOutputStream(outputf);        PrintWriter pw = new PrintWriter(fos);        while ((read = bufread.readLine()) != null) {            write = read.replaceAll(regex, "")+"\r\n";            pw.write(write.toCharArray());        }        pw.flush();        pw.close();        System.out.println("处理完成!");        System.out.println("请查看文件:"+outputf.getAbsolutePath());    }    /**     * 创建文本文件.     *      * @throws IOException     *      */    public static File creatTxtFile(String filename) throws IOException {        File f = new File(filename);        if (!f.exists()) {            f.delete();            f.createNewFile();        }        return f;    }}
相关栏目:

用户点评