Solved

Reading a file using FileReader

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

863 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

19 Experts available now in Live!

Get 1:1 Help Now