1

I am writing a program where I am reading from a file, and the separator for my file data is a blank line, just whitespace, and I want to skip it whenever I get to it. My expression for reading from the file is String[] array = f.nextLine(" "). I tried putting conditions after this line, something like if(array.length == 0) or if (array == null), but it doesn't seem to get into these.

Vlad Nicola
  • 179
  • 2
  • 9
  • 9
    Instead of describing your code, [edit] your question to include the code relevant to your question (a [mcve] would be even better). – azurefrog Jan 08 '18 at 18:57
  • Possible duplicate of [How do I check that a Java String is not all whitespaces?](https://stackoverflow.com/questions/3247067/how-do-i-check-that-a-java-string-is-not-all-whitespaces) – Bernhard Barker Jan 08 '18 at 19:10

1 Answers1

1

For white space first trim the line:

line.trim();

And then check if it's null:

if (line.equals(""));

Then split it by using:

String[] array = line.split (" ");

This will help!

Joza100
  • 338
  • 4
  • 16