-
reading from text file to 2d array
Could someone please tell me why I get a NullPointerException?
System.out.print("Enter the name of the file: ");
String fileName = readInput();
BufferedReader br = new BufferedReader(new FileReader(fileName + ".txt"));
String line;
int rowIndex = 0;
String matrix [][] = null;
while ((line = br.readLine()) != null) {
StringTokenizer st = new StringTokenizer(line);
int colIndex = 0;
while (st.hasMoreTokens()) {
matrix [rowIndex][colIndex++] = st.nextToken().trim();
}
}
rowIndex = rowIndex + 1;
br.close();
}
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