Hi there;
There is such a simple code here, and with the propotion of its simplicity, it drives me crazy.
Here is the code:
private void fillArrayLists(String fileName,ArrayList <String> list)
{
try{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream(fileName);
// 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.trim());
list.add(strLine.trim());
}
//Close the input stream
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
It simply reads the input and fills proper arraylist.
I call them such like that:
System.out.println("*** RANKS: ***");
fillArrayLists("ranks.txt" , this.ranks);
System.out.println("*** Departments: ***");
fillArrayLists("departments.txt" , this.departments );
System.out.println("*** names: ***");
fillArrayLists("names.txt", this.names);
System.out.println("*** surnames: ***");
fillArrayLists("surnames.txt", this.surnames);
RANKS printed such as:
*** RANKS: ***
��t��u��g��g��e��n��e��a��l instead of "tuggeneral"
surnames are bad as mentioned above. But names and departments are printed as expected.
Why?