Re: Beginner CSV error
- From: "Monique Y. Mudama" <spam@xxxxxxxxxxxxxxxx>
- Date: Mon, 30 Jan 2006 13:30:06 -0700
On 2006-01-30, Rob penned:
> I am trying to read in CSV data. "test.scv"'s contents are:
>
> 1,2,3
> 4,5,6
> 7,8,9
>
> My code is:
>
> import java.io.*;
> import com.Ostermiller.util.*;
> class csvtest {
> public static void main(String[] args) {
> String[][] data = (new CSVParser(new
> FileReader("test.csv"))).getAllValues();
> System.out.println(data);
> }}
>
> The errors are:
>
> unreported exception java.io.FileNotFoundException; must be caught or
> declared to be thrown
>
> String[][] data = (new CSVParser(new
> FileReader("test.csv"))).getAllValues();
> Note: .\com\Ostermiller\util\CSVParser.java uses unchecked or unsafe
> operations.
>
> Thank you for your help
>
> Rob
You need to put a try block around the line that invokes the
FileReader constructor. Then you need to put a catch block right
below the try block that catches the exception that the FileReader
constructor can throw.
Do you understand exceptions and how to work with them? The
FileReader constructor can throw an exception if it doesn't find the
file you specify. Because it can throw that exception, you need to
catch it and figure out what to do about it.
--
monique
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
.
- References:
- Beginner CSV error
- From: Rob
- Beginner CSV error
- Prev by Date: Re: Beginner CSV error
- Next by Date: Re: How to check/validate XML against XSD
- Previous by thread: Re: Beginner CSV error
- Next by thread: Re: Beginner CSV error
- Index(es):
Relevant Pages
|
|