Hello, I am very new to the Java world and I have a small problem, I currently want to save a text from a .txt file in a variable String, but with the little knowledge I have of Java I did something very rudimentary that also does not work well because reading the variable "text" which is where I store the .txt information shows me the following: "nullThis is a test".
(This is a test) is the content of the txt.
I hope that some wise person can help me thank you in advance.
public class Acceso_fichero {
public static void main(String[] args) {
Leer_fichero accediendo=new Leer_fichero();
accediendo.lee();
}
}
class Leer_fichero{
String texto;
public void lee() {
try {
FileReader entrada=new FileReader("C:/Users/Etchko/Desktop/leeme.txt");
int c=0;
while(c!=-1) {
c=entrada.read();
char letra=(char)c;
texto+=letra;
}
entrada.close();
System.out.println(texto);
} catch (IOException e) {
System.out.println("No se ha encontrado el archivo");
}
}
}