first debug problem in my code
Hi,
I am a beginner in Java for a project but I have lots of experience in C++ and Matlab! Now I use eclipse as an environment to program. To know java and eclipse better I started with a class where I can load a txt file with. also I try to organize the code like I was used to in C++. I have two questions for my following code below:
package readOMIM;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
/**
* This program reads a text file line by line and print to the console. It uses
* FileOutputStream to read the file.
*
*/
class aap {
// Objects
File file = null;
FileInputStream fis = null;
BufferedInputStream bis = null;
DataInputStream dis = null;
void LoadFile(String name)
{
File file = new File(name);
try
{
fis = new FileInputStream(file);
// Here BufferedInputStream is added for fast reading.
bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
//fis.close();
//bis.close();
//dis.close();
//while (dis.available() != 0)
{
// this statement reads the line from the file and print it to
// the console.
// System.out.println(dis.readLine());
}
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
void ShowContent()
{
//dis.available();
// dis.available() returns 0 if the file does not have more lines.
if (dis.available())
{
// this statement reads the line from the file and print it to
// the console.
//System.out.println(dis.readLine());
}
}
}
public class readOMIM {
public static void main(String[] args) {
aap omimsite;
omimsite = new aap();
omimsite.LoadFile("C:\\Documents and Settings\\hvanhaagen\\" +
"My Documents\\OMIM\\genemap.txt");
omimsite.ShowContent();
}
}
Now the compiler tells that this code is not legal because of the following statement:
if (dis.available())
I don't know why? I think it is a simple starting problem of mine! yet my second question is about the structure. I like to organize my classes with a header file like in C++. So only the declaration of a method in a class and the implementation outside. They maybe be in the same file but at the top you can see fast how the class is organized.
Thank you!
Herman
|