Solved

Reading a file using FileReader

Posted on 2011-03-10
5
435 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

617 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