• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Basic File read in Java not working

Avalon

Diamond Member
I'm actually pretty good with Java, and had just completed my first programming assignment on my new computer. Only problem was, is that my file read was not properly reading files, so I just commented it out and just took the inputstream for my assignment at the time. But, now that I have some time to think about it, I went and wrote a simple file read program, and it's giving me the same problems. Perhaps I'm having coder's block, but I was hoping you guys could tell me what I was doing wrong. Here's the code:

import java.io.*;

class FileReadTest {

public static void main (String[] args) {

try {

String record = null;
FileReader fr = new FileReader("C:\\Homework\\prog.txt");
BufferedReader br = new BufferedReader(fr);

record = br.readLine();

System.out.println(record);

}//end try

catch(IOException e){

System.out.println(e);

}//end catch

}//end main

}//end FileReadTest

Where this program is compiled (successfully) in my C:\Homework folder along with the file "prog.txt". I can also do FileReader fr = new FileReader("prog.txt"); and get the same error upon runtime, which is:

"java.io.FileNotFoundException: C:\Homework\prog.txt (The system cannot find the file specified)"

My OS is Vista64 Ultimate, and I'm using the very latest Java SDK. Thoughts?
 
ROFL, nm. I accidentally named my read file prog.txt, so the program was looking for prog.txt when on the system it was prog.txt.txt. Wow, talk about a brain fart.
 
Back
Top