• 删除txt中不要的字符


    在对生成数据集的时候,我们需要有语料,一般是写在txt中的,我们如何去掉不要的字符,比如说●

    具体思路是,1.txt是字典,2.txt是语料,3.txt是去掉不要字符之后的文本。2.txt逐个字符进行遍历跟1.txt比对,有就写在3.txt中没有就跳过

    创建一个app.java文件

    在linux中编译:javac app.java

    运行:java app

    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.Reader;
    import java.io.Writer;
    
    public class app {
        public static void main(String[] args) throws IOException{ 
            File file = new File("2.txt");
            Reader fr = new FileReader(file);                    
            Writer fw = new FileWriter("3.txt", false);
            
            int len = fr.read();
            while (-1 != len){
                //System.out.println("=="+len);
                //if(len!=10 && find(len)==1)//全部写成一行
                if(find(len)==1)//取消换行
                    fw.write(len);
                len = fr.read();
            }
            
            fw.flush();
            fw.close();
            fr.close();
        }
        public static int find(int x) throws IOException{
            File file = new File("1.txt");
            Reader fr = new FileReader(file);
            int len = fr.read();
            while (-1 != len){
                if(len==x){
                    fr.close();
                    return 1;
                }
                len = fr.read();
            }
            fr.close();
            return 0;
        }
    }
     
  • 相关阅读:
    09、AppBarControl
    15、ScrollViewerSample
    11、DataBinding
    18、Compression
    关于创建oracle dblink 过程的几点心得吧
    教你如何玩转DK血
    DK需要知道的事
    Displaying Dynamic KML with ASP.NET
    WLK:裁缝/附魔350450速冲攻略
    WLK狂暴,防御战士的一点心得.
  • 原文地址:https://www.cnblogs.com/j657521265/p/9429271.html
Copyright © 2020-2023  润新知