Solved

Reading a file using FileReader

Posted on 2011-03-10
5
433 Views
Last Modified: 2012-05-11
I have a file called error.txt that exists on the classpath - How can I read this file using the FileReader class.
This file exists in com.test.errors package.

Thanks in advance
0
Comment
Question by:singh101
  • 3
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 35094949
That would depend on what package you're in when reading it. Assuming the same, try:
Reader in = new FileReader(new InputStreamReader(getClass().getResourceAsStream("error.txt")));

Open in new window

0
 

Author Comment

by:singh101
ID: 35094968
Its complaining that the constructer in FileReader is undefined for InputStreamReader
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 35095018
Sorry, try
Reader in = new InputStreamReader(getClass().getResourceAsStream("error.txt"));

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35095360
:)
0
 
LVL 92

Expert Comment

by:objects
ID: 35099974
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question