void ReadFile() throws Exception
{
FileReader file = new FileReader(File_name);
BufferedReader reader = new BufferedReader(file);
String text ="";
String line = reader.readLine();
while(line != null)
{
text += line; //text is assigned the string value that was in the buffer
line = reader.readLine();//reads next line
}
System.out.println(text);//once end of file was reached the String is printed
reader.close();
}
I am reading Java the complete Reference Eighth Edition and it is rather frustrating how many ways there are to handle files. The above example seems to be pretty simple, is this the most common way? What is your favorite and why?
Lets say I wanted to break down the input because I new the file format, is DataInputStream the simplest and efficient way to handle that? I know you already told me about one way to handle this but since there were some many ways to handle files I figured there was something designed for such a thing.
Which leads me to my next question:
struct foo
{
int age;
std::String DOB;
std::String Name;
}MyFoo
std::list<MyFoo>Mylist; //here I could call push after I got all the data from the file like I explained above
int main()
{
//some stuff
}
What is a good way to handle this in Java? Java doesn't have structs but it does have inner classes. Is that what I need here?