Re: Beginner CSV error



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
.



Relevant Pages

  • Re: [Newbie] Reading & Writing Objects To File
    ... | java.io.StreamCorruptedException exception. ... |>> public static void main(Stringargs) ... |>> new CardCreatorDump(); ...
    (microsoft.public.dotnet.vjsharp)
  • Re: crushing java
    ... your reaction just proved you to be sentimental and self blinded ... public static void Main(stringargs) ... }catch(Exception e) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: crushing java
    ... your reaction just proved you to be sentimental and self blinded ... public static void Main(stringargs) ... }catch(Exception e) ...
    (microsoft.public.dotnet.framework)
  • Re: problem...sorry my first time with java
    ... public static void main{ ... java cl_gm ... the String array passed to the main method as args[] will be empty, ... You may wish to familiarise yourself with the javadoc for the exception ...
    (comp.lang.java.help)
  • Re: I need to know if a java class import a package
    ... to test if they can iterate an order an array by themselves). ... public static void main(Stringargs) throws Exception { ...
    (comp.lang.java.programmer)