Reputation: 97
I was curious if I could read a text file from my computer on an android phone using FileReader and Buffered Reader class. Is the text file loaded onto the android phone from my desktop when the application begins?
This is the only relevant section of my code. I know the catch part is not there.
public void TestSeizureDetected() throws FileNotFoundException {
try {
FileReader fr = new FileReader("C:/Users/desiyosh/Desktop/patient1.txt");
BufferedReader textReader = new BufferedReader(fr);
String[] temp = new String[7681];
double[] convert = new double[7681];
for(int z= 0; z<7861; z++) {
temp[z] = textReader.readLine();
}
textReader.close();
}
}
Upvotes: 1
Views: 65
Reputation: 76001
No, this will not work.
The phone and the computer are two separate computer devices, and the file system of your computer is not automatically mounted to your phone. Even when connected through USB cable.
Furthermore, even if it was, the Android OS is based on Linux, so it does not understand the Windows OS volumes like C:, and as such the path you've provided will be invalid path.
Also, you want to put the file name in parentheses, like this - "C:/Users/desiyosh/Desktop/patient1.txt"
, or the Java compiler will yell at you.
Upvotes: 3