I'm trying to read a properties file using BufferedInputSt ream and getResourceAsSt ream(),but getting "java.io.IOExce ption: Stream closed' exception.
My properties file is not set in the classpath, I even tried by incuding the file as a jar in the classpath but invain.
My code snippet is:
BufferedInputSt ream bufferedinputst ream =new BufferedInputSt ream(getClass() .getClassLoader ().getResourceA sStream(s));
where 's' is the name of the properties file.
I'm running as a standalone program.
Can anyone help me out in resolving the issue.
5 11748
I'm trying to read a properties file using BufferedInputSt ream and getResourceAsSt ream(),but getting "java.io.IOExce ption: Stream closed' exception.
My properties file is not set in the classpath, I even tried by incuding the file as a jar in the classpath but invain.
My code snippet is:
BufferedInputSt ream bufferedinputst ream =new BufferedInputSt ream(getClass() .getClassLoader ().getResourceA sStream(s));
where 's' is the name of the properties file.
I'm running as a standalone program.
Can anyone help me out in resolving the issue.
The class that has the code u have given above must throw IOException
public class Test
{
public static void main (String Args []) throws IOException{
BufferedInputSt ream bis = new BufferedInputSt ream(new FileInputStream ("mydata.proper ties"));
DataInputStream dis = new DataInputStream (bis);
try {
String st=dis.readLine ();
if(st!=null){
System.out.prin tln(st);
}
} catch (Exception e) {
e.printStackTra ce();
}
}
This is a sample code that works properly.I have placed the property file in the root path itself.
...
This is a sample code that works properly.I have placed the property file in the root path itself.
No, that is not how you're supposed to read a Properties file. Here's how: - FileInputStream fis = new FileInputStream("C:/Temp/test.properties");
-
Properties props = new Properties();
-
props.load(fis);
-
fis.close();
-
-
// ...
-
-
System.out.println(props.get("key"));
@OP: Are you perhaps closing the stream before you call Properties' load(...) method?
JosAH 11,448
Recognized Expert MVP
Using getResourceAsSt ream() isn't that wrong. It allows for streams to be
opened in jars etc. Just get the path to the resource right and that's it.
Specify the path to the resource either somewhere external or just relative to
where the class itself (the one that invokes the resourceAsStrea m() method)
is located. It works for me; all the time ;-)
kind regards,
Jos
Using getResourceAsSt ream() isn't that wrong. It allows for streams to be
opened in jars etc. Just get the path to the resource right and that's it.
Specify the path to the resource either somewhere external or just relative to
where the class itself (the one that invokes the resourceAsStrea m() method)
is located. It works for me; all the time ;-)
kind regards,
Jos
I was talking about the solution proposed in reply #2 where someone suggested to read the properties file line by line like an ordinary (text) file.
; )
JosAH 11,448
Recognized Expert MVP
I was talking about the solution proposed in reply #2 where someone suggested to read the properties file line by line like an ordinary (text) file.
; )
Ah, yes; I missed that; sorry about that; reading the properties thing yourself is
certainly not the way to go; the Properties object does more than reading lines,
e.g. it also converts those \u unicode escape sequences. wheels and reinventions
and all that ;-)
kind regards,
Jos
ps. I removed some more noise words from your SV text; that size on disk is
down from ~ 3.5MB to ~ 3.1MB ;-)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: syntax |
last post by:
hi, i want to read a file using fread() in equal chunks through a for
loop so that at the last call i dont get error..which way, i should
read it?
let me give an example, suppose i have 100 chars, i can read it in 50
chars for twice or 10 chars in ten times or 25 chars for 4
times...like this. Here, file size, i.e 100 chars is known to
me....but if the file size is unknown then how can i read in equal
chunks so that at the last call i...
|
by: Drew Yallop |
last post by:
I read an XML file with a stream reader in VB.Net. When I
look at the stream reader output in debug mode (by
passing cursor over the stream reader object)the format
is a perfect replica of the file as displayed when I open
the xml file in VS .net 2003 IDE.
When I perform the same procedure in C# the stream reader
obkect displays a chaotic mess. Lots of whitespace after
and "\r" and "\n" after each element. The problem is that
I cannot...
|
by: Simon Verona |
last post by:
Not sure if this is the best group... it may be better off in one of the ADO
groups, but I'm sure somebody here knows the answer:
I'm trying to load up a text file using ADO.net, as follows:
Dim TextConnectionString As String
TextConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & FilePath & ";" & _
|
by: JM |
last post by:
Hi,
I have been trying to read a file, using "StreamReader" to pass the info to
an string that is:
....dim stream as new FileStream(file,...)
dim sr as new StreamReader(stream)
dim data as string = sr.ReadToEnd...
My problem is that in the file (is a text file) there is some data like:
|
by: richard.kessler |
last post by:
I have the simplest need...to read a file full of file names(unc) and
then check to see if each of these files exists. I tried with the
following program, but always get file not found, even when it is
there. If I type in the file name as a literal it works...
Little program:
#This module checks for file existence
import string
import sys
| |
by: tshabza |
last post by:
Could anyone give me idea on how to read a wave and convert in into an integer array file using C++, for now I can successfullly read text file.
|
by: tourist.tam |
last post by:
Hi,
I am trying to read a file using a BufferedStream and avoiding at
maximum the use of string manipulation. I need now some help
understanding on how to use byte array to hold the data and manipulate
those. I do understand that I will have to pass any of the array
created into strings at the end of the process. But I am missing the
intermediate steps. And being just introduced to JAVA, my
understanding of processing large plain text...
|
by: tushar.saxena |
last post by:
Hi,
I'm trying to read a file using the istearm class (I cant use ifstream
since the input might be a file or it might be stdin).
istream *input;
// Add checks for file name here, else use input = &cin;
while (!input->eof())
|
by: tshad |
last post by:
I have a program that is reading a csv file into a dataset. I want it to
read the 1st line as data. But it ignores it.
I have the Connection set up as:
OleDbConnection csvConnection = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
csvPath + ";Extended
Properties=\"Text;HDR=Yes;FMT=Delimited\"");
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |