-
Returning a multidimensional array from a method in a jsp
Hi,
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;
}
%>
-
Declare importArray outside the try block then it should work
-
Thank you
declaring and initializing outside the try worked.
Casey
Similar Threads
-
By fulcanelli in forum Java
Replies: 2
Last Post: 11-10-2005, 01:33 PM
-
Replies: 5
Last Post: 11-04-2005, 02:53 PM
-
By kanakatam in forum Java
Replies: 2
Last Post: 04-15-2005, 09:06 PM
-
Replies: 4
Last Post: 03-29-2005, 06:26 PM
-
Replies: 2
Last Post: 03-03-2001, 11:50 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks