• Post Reply Bookmark Topic Watch Topic
  • New Topic

File is Not Recognized to read  RSS feed

 
leela krishhna
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!