Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

220
Views
Java - Quirk with reading lines from a Path

I seem to be having a randomly occurring issue that I hope someone can shed light on. I am reading in a file and outputting the contents. I have one test file, which can be read in 90% of the time. However, once in a while it incorrectly reports that the test file has 0 lines. Is there a reason this is happening? I would expect that it always reads in the contents. A bare bones example is shown below:

public void foo (Path path){
    System.out.println("Exists?"+ Files.exists(path)); // Always says true
    List<String>lines = Files.readAllLines(path);
    System.out.println("NumLines:"+ lines.size()); // Sometimes 0, sometimes 7
}

I have also tried this with a BufferedReader(new FileReader(path.ToFile())) and get the same results

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!