Returning a multidimensional array from a method in a jsp
I was wondering if anyone could tell me how to return a 2d array from a method im using in a jsp page (im not sure how this will differ from other java programming) I'll put my code below if that helps.
I get the error located on the return statement line at the bottom that "importArray cannot be resolved" and if I add brackets to the importArray on the return statement "return importArray[][];" I get anther error that I should add a ";" to complete the return statement.
Any help would be appreciated.
thanks
Casey
<%!
static String[][] readCSV(File importFile)
{
String fileContents = "";
StringBuffer contents = new StringBuffer();
BufferedReader input = null;
int linecount = 0;
try
{
input = new BufferedReader (new FileReader(importFile));
String line = null;
while((line = input.readLine()) != null)
{
contents.append(line);
contents.append(System.getProperty("line.separator"));
}
if (input != null)
{
input.close();
}
fileContents = contents.toString();
StringTokenizer row = new StringTokenizer(fileContents, "\n");
int rowNum = row.countTokens();
String nextRow = row.nextToken();
StringTokenizer col = new StringTokenizer(nextRow, ",");
int colNum = col.countTokens();
String[][] importArray;
importArray = new String[rowNum][colNum];
rowNum = 0;
colNum = 0;
while(row.hasMoreTokens())
{
StringTokenizer field = new StringTokenizer(nextRow, ",");
while(field.hasMoreTokens())
{
String nextField = field.nextToken();
importArray[rowNum][colNum] = nextField;
colNum++;
}
nextRow = row.nextToken();
rowNum++;
colNum = 0;
}
rowNum = 0;
}
catch (Exception e)
{
System.out.println("Exception: " + e.getMessage());
}
return importArray;
}
%>

