| Author |
File is Not Recognized to read
|
leela krishhna
Greenhorn
Joined: Aug 24, 2012
Posts: 7
|
|
In the below Code, i have the File qwer.vmg, which is not reading..
It showing errors.. how can i read that file...
Please give me solution.. or way to solve it...
import java.io.*;
class FileRead
{
public static void main(String args[])
{
try{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("qwer.vmg");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
}
//Close the input stream
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
|
 |
Jeff Verdegan
Bartender
Joined: Jan 03, 2004
Posts: 5891
|
|
You need to TellTheDetails(⇐click). Copy/paste the exact, complete error message, and indicate clearly which line is causing it.
Also, when posting code, please UseCodeTags(⇐click) so it will be readable.
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
You have three possibilities to fix that problem (based on a guess at what those error messages might have said):
1. Change your current working directory to the one which that file is in.
2. Move that file to the directory which is your current working directory.
3. Put the full path to the file in your code.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
You should also consider what format that file is. Is it text, binary or what?
I have taken the colours out of your post; some people find coloured text difficult to read. Code tags would have allowed you to indent it.
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
I also have the question of why you are using a DataInputStream if you're just going to treat the file as text and read it line by line. However I'm going to wait until I see the error messages before I say anything else.
|
 |
 |
|
|
subject: File is Not Recognized to read
|
|
|