Java reads a large text file with separator

advertisements

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

datadfqsjmqfqs+dataqfsdqjsdgjheqf+qsdfklmhvqziolkdsfnqsdfmqdsnfqsdf+qsjfqsdfmsqdjkgfqdsfqdfsqdfqdfssdqdsfqdfsqdsfqdfsqdfs+qsfddkmgqjshfdfhsqdflmlkqsdfqdqdf+

I want to read this string in the text file as one big java String. Is this possible? I know the use of the split method.

It worked to read it line by line, but what I really need is to split this long text-string at the '+' sign. Afterwards I want to store it as an array, arraylist, list,...

Can anyone help me with this? Because every information on the internet is just about reading a file line by line. Thanks in advance!


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();
            }
        }