I'm trying to read a text file in a specific package but it return that couldn't be found.I can read it inserting the absolute path but i want to read it without inserting the absolute path.
String texto = "Utils/CEP/Cidades/" + estado + ".txt";
FileReader fr = new FileReader(texto);
BufferedReader in = new BufferedReader(fr);
How should i do?
Thanks
You can use
InputStream in =
getClass().getResourceAsStream("/Utils/CEP/Ciades/" + estado + ".txt");
Reader fr = new InputStreamReader(in, "utf-8");
A few sidenotes: don't use capital letters in package names; use English names of your variables. These are accepted practices and conventions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With