Solved

Reading a file using FileReader

Posted on 2011-03-10
5
429 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
Comment Utility
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
Comment Utility
Its complaining that the constructer in FileReader is undefined for InputStreamReader
0
 
LVL 86

Accepted Solution

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

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
:)
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now