hello all
i am now about ready to pull my hair out and/or possibly worse!
i have to read a .csv file, split the 3 elements into variables and then put two of the variables into a map. i can read the file fine, i can display the variables in my test environment fine, but can i get them into the map.....nope
if anyone can tell me where i'm going wrong it would be great, as i'm ready to give up! i've read and read and read my text book and cant see where i'm going wrong. i'm not asking for the answer just a what i should do.
/**
* Prompts the user for a pathname and then attempts to open a stream
* on the specified file. The method expects a file containing the details
* of target values in CSV format and will return a collection of TrialAdmin objects
* constructed from those details
*/
public void readInTasks()
{
String pathname = OUFileChooser.getFilename();
File aFile = new File(pathname);
BufferedReader bufferedFileReader = null;
Map<Integer, Integer> targetMap = new TreeMap<Integer, Integer>();
try
{
bufferedFileReader = new BufferedReader(new FileReader(aFile));
String currentLine = bufferedFileReader.readLine();
//Map<Integer, Integer> targetMap = new TreeMap<Integer, Integer>();
while (currentLine != null)
{
Scanner lineScanner = new Scanner(currentLine);
lineScanner.useDelimiter(",");
taskNumber = lineScanner.nextInt(); //return the next token as an integer
version = lineScanner.next(); // return the next token as a string
pitchTarget = lineScanner.nextInt(); // return the next token as a double
System.out.println(taskNumber + " - " + pitchTarget);//check to see if file is read
[icode] targetMap.put(taskNumber, pitchTarget); //this is the line that doesn't work[/icode]
currentLine = bufferedFileReader.readLine(); //get the next line
}
}
catch (Exception anException)
{
System.out.println("Error: " + anException);
}
finally
{
try
{
bufferedFileReader.close();
}
catch (Exception anException)
{
System.out.println("Error: " + anException);
}
}
}