Java read large text file with separator

后端 未结 6 860
悲哀的现实
悲哀的现实 2020-12-21 20:00

I\'m trying to read a large text file in the form of:

datadfqsjmqfqs+dataqfsdqjsdgjheqf+qsdfklmhvqziolkdsfnqsdfmqdsnfqsdf+qsjfqsdfmsqdjkgfqdsfqdfsqdfqdfssdqd         


        
6条回答
  •  渐次进展
    2020-12-21 20:22

    You can read file using BufferedReader or any IO-classes.suppose you have that String in testing.txt file then by reading each line from file you can split it by separator (+). and iterate over array and print.

    BufferedReader br = null;
        try {
            String sCurrentLine;
            br = new BufferedReader(new FileReader("C:\\testing.txt"));//file name with path
            while ((sCurrentLine = br.readLine()) != null) {
                   String[] strArr = sCurrentLine.split("\\+");
                   for(String str:strArr){
                        System.out.println(str);
                          }
                }
    
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    if (br != null)br.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
    

提交回复
热议问题