This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes File is Not Recognized to read Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "File is Not Recognized to read" Watch "File is Not Recognized to read" New topic
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
    
    6

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
    
    2

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
    
    4
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
    
    2

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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: File is Not Recognized to read
 
Similar Threads
Why do i get NoClassDefFound error??
command line arguments for a file
Regarding reading a file in a jsp
Reading one line from a text
to read lines inside brackets