Choose an "x" file inside a java directory

Asked

Viewed 498 times

1

So I’m doing a project and in it I would have to fetch some keywords in files. txt within a given directory, only that the name of these files does not follow a pattern and my program would have to read 1 by 1. I wonder if there is any method in Java that can select a file based only on its directory and the position it is in it, for example "find the path of the 3 file in the folder such"

  • What would your read? These are *.TXT files and you will have to access the contents of the files?

  • This, sorry, I will edit the question, but are txt files and I would have to run the text in search of some keywords

  • But the part of extracting the text I already did, the problem in question would be the path of each file since the names are not standardized.

  • Take a look at this question, see if it helps you https://answall.com/questions/159928/ler-filename-of-interno/159934#159934 I believe this is just what you need

  • That’s right, bro, they fight for help!

1 answer

0


public static void getImgs(String path){
File file = new File(path); // Diretório dos arquivos
File[] arquivos = file.listFiles();

for (File arquivo : arquivos) {
    System.out.println(arquivo); // Exibe o nome dos arquivos no diretório determinado
}
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.