Solved

Reading a file using FileReader

Posted on 2011-03-10
5
432 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
egit plugin on eclipse 8 82
Why my table column Id is not passed to java object? 4 44
jsp login check 12 42
Eclipse Java import and method not resolved 4 48
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

860 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