Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

221
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda