FileReader() constructor issue in Eclipse?? [message #210374] |
Fri, 11 May 2007 12:29 |
Eclipse User |
|
|
|
Originally posted by: stedav.stevedavies.gmail.com
Hi,
I'm trying to create a basic File io reader to read from a text file in
Eclipse. I start with the usual try/catch block for IOExceptions. here
is an example of my code:
FileReader fr = new FileReader("lorum.txt") //a simple txt file I have
However in Eclipse at this stage I get a red underline error saying
"the constructor FileReader(String) is undefined."
I have tried also creating a new File Object (File myFile = new
File("lorum.txt"); and then chaining it to a FileReader but still I have
no success. In the Java API it says FileReader class takes a String
constructor argument (String) which is what I have tried in the first
sense "lorum.txt"
Is this an issue with my Code or a problem n Eclipse??
Stedav
|
|
|
Re: FileReader() constructor issue in Eclipse?? [message #210424 is a reply to message #210374] |
Fri, 11 May 2007 14:03 |
Eclipse User |
|
|
|
Originally posted by: eclipse5.rizzoweb.com
Steve Davies wrote:
> Hi,
>
> I'm trying to create a basic File io reader to read from a text file in
> Eclipse. I start with the usual try/catch block for IOExceptions. here
> is an example of my code:
>
> FileReader fr = new FileReader("lorum.txt") //a simple txt file I have
>
> However in Eclipse at this stage I get a red underline error saying
> "the constructor FileReader(String) is undefined."
Check the import statement and make sure that the FileReader you are
using is actually java.io.FileReader and not some other class in a
different package.
Hope this helps,
Eric
|
|
|
Re: FileReader() constructor issue in Eclipse?? [message #210440 is a reply to message #210424] |
Fri, 11 May 2007 14:05 |
Eclipse User |
|
|
|
Originally posted by: stedav.stevedavies.gmail.com
Eric Rizzo wrote:
> Steve Davies wrote:
>> Hi,
>>
>> I'm trying to create a basic File io reader to read from a text file
>> in Eclipse. I start with the usual try/catch block for IOExceptions.
>> here is an example of my code:
>>
>> FileReader fr = new FileReader("lorum.txt") //a simple txt file I have
>>
>> However in Eclipse at this stage I get a red underline error saying
>> "the constructor FileReader(String) is undefined."
>
> Check the import statement and make sure that the FileReader you are
> using is actually java.io.FileReader and not some other class in a
> different package.
>
> Hope this helps,
> Eric
Thanks Eric,
but i have tried both
import java.io.*;
and
import java.io.FileReader.*;
Ill keep trying
|
|
|
Re: FileReader() constructor issue in Eclipse?? [message #210461 is a reply to message #210440] |
Fri, 11 May 2007 15:55 |
Eclipse User |
|
|
|
Originally posted by: wharley.bea.com
"Steve Davies" <stedav.stevedavies@gmail.com> wrote in message
news:f21t87$t1h$1@build.eclipse.org...
> but i have tried both
>
> import java.io.*;
>
> and
>
> import java.io.FileReader.*;
If you type "FileReader f;" and Ctrl+click on the FileReader typename, does
it jump you to the expected class, and does that class show a String
constructor?
For what it's worth, in Eclipse 3.2.2 I have no problem using the String
constructor for FileReader; e.g., the following class compiles:
import java.io.*;
public class Foo {
void foo() {
FileReader f = null;
try {
f = new FileReader("foo.txt");
f.reset();
} catch (IOException e) {
// ignore
} finally {
try {
if (null != f) {
f.close();
}
} catch (IOException e) {
// ignore
}
}
}
}
So I think it must be something funky going on either with your code or with
the JRE you are using.
What version of Eclipse are you using, and what JRE is on your project's
build path?
|
|
|
|
Powered by
FUDForum. Page generated in 0.08028 seconds