0
public ArrayList makeList(String FileStr, File mainFile) {
    ArrayList file_reader = new ArrayList();
    boolean flag = false;

    try {
        if (FileStr.contains(".txt")) {
            BufferedReader bufferedReader = new BufferedReader(new FileReader(mainFile));
            String thisLine = null;
            while ((thisLine = bufferedReader.readLine()) != null) {
                if (thisLine != null && !thisLine.isEmpty()) {
                    flag = true;
                    file_reader.add(thisLine);
                }
            }
            if (bufferedReader != null) {

                bufferedReader.close();
            }

        }
    } catch (IOException ex) {
        // Logger.getLogger(BulkUpload.class.getName()).log(Level.SEVERE, null, ex);
        ex.printStackTrace();
    }


    if (flag) {
        return file_reader;
    } else {
        return null;
    }
}

I have written this code to read lines from the file, but if there is a blank line in between 5000 records, the front end goes blank.

How can I manage this blank space?

I dont want to stop reading my files even though there is a blank space or line in between records

lxcky
  • 1,668
  • 2
  • 13
  • 26
  • 1
    Are you sure the blank line is the problem? I don't see anything in your code that suggests that it would stop reading if it encounters a blank line. – Robby Cornelissen Aug 30 '14 at 05:36
  • Can you show us your stack trace? It's hard to know why your screen is going blank. And I think @RobbyCornelissen is right, it seems that it has nothing to do with blank lines. – lxcky Aug 30 '14 at 05:50

2 Answers2

1

if (thisLine.trim().isEmpty())

Alex Suo
  • 2,977
  • 1
  • 14
  • 22
1

Blank lines don't give you null. They just give you empty string or blank spaces. You can avoid them using two ways.

1st way

 if(thisLine.trim().equals(""))
        continue;

2nd Way

if(thisLine.trim().length()<1)
        continue;

Hope that helps.

Prazzy Kumar
  • 994
  • 1
  • 11
  • 16