Hey,
The following code tries to read a text file "myFile.txt" and store the contents of this file into a String variable called "strFileData" and then output this variable to standard output.
It does'nt work!
Why does this variable contain integers?
Where is the string contents of "myFile.txt"?
If anyone has another way of doing this then tell me!
Thanks,
Steve.
The following code tries to read a text file "myFile.txt" and store the contents of this file into a String variable called "strFileData" and then output this variable to standard output.
It does'nt work!
Why does this variable contain integers?
Where is the string contents of "myFile.txt"?
If anyone has another way of doing this then tell me!
Thanks,
Steve.
Code:
String strFileData = "";
try
{
File file = new File("myFile.txt");
FileReader fileReader = new FileReader(file);
int data;
while ((data = fileReader.read()) != -1)
{
System.out.write(data);
strFileData += data;
}
fileReader.close();
}
catch (IOException io)
{
}
System.out.println(strFileData); // outputs rubbish!