Results 1 to 16 of 16
- 05-31-2010, 02:39 PM #1
Member
- Join Date
- May 2010
- Posts
- 5
- Rep Power
- 0
Stream closed on a ClassLoader input
Here is my code (yes, I know part of it isn't used anymore):
and my problem:public static boolean comparePasswords(String input) throws IOException{
String password = "";
String file = "src/password.spm";
FileInputStream passwordRead = new FileInputStream(file);
BufferedInputStream passwordBuffer = new BufferedInputStream(ClassLoader.getSystemResourceA sStream(file));
DataInputStream passwordInput = new DataInputStream(passwordBuffer);
while(passwordInput.available() != 0){ //<---- Here is the error
password = passwordInput.readLine();
}
if(encrypt(input).equals(password)){
return true;
}
else{
return false;
}
}
I don't close the stream anywhere, so I don't understand what it is whining about - can "ClassLoader.getSystemResourceAsStream(file)" not be used like that?Exception in thread "main" java.io.IOException: Stream closed
at java.io.BufferedInputStream.getInIfOpen(Unknown Source)
at java.io.BufferedInputStream.available(Unknown Source)
at java.io.FilterInputStream.available(Unknown Source)
at login.login.comparePasswords(login.java:29)
at login.login.main(login.java:73)
- 05-31-2010, 04:11 PM #2
Check the file path once.
Ramya:cool:
- 05-31-2010, 05:27 PM #3
Member
- Join Date
- May 2010
- Posts
- 5
- Rep Power
- 0
Yes? It is not a FileNotFound error, which it was initially, until I changed it to what it says now.
- 05-31-2010, 05:47 PM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
What you've here?
login.login.main(login.java:73)
- 05-31-2010, 06:12 PM #5
Member
- Join Date
- May 2010
- Posts
- 5
- Rep Power
- 0
Just a main to check it.public static void main(String[] args) throws IOException{
String password = "hej";
System.out.println(encrypt(password));
System.out.println(comparePasswords(password));
}
- 05-31-2010, 06:18 PM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Is those display the correct/expected values?
Java Code:System.out.println(encrypt(password)); System.out.println(comparePasswords(password));
- 05-31-2010, 06:20 PM #7
Member
- Join Date
- May 2010
- Posts
- 5
- Rep Power
- 0
The first one is, but the second is where it bugs, because it calls my comparePasswords.
- 05-31-2010, 07:26 PM #8
How/where is the code being executed?
What jdk and jre are you using?
- 05-31-2010, 08:05 PM #9
Member
- Join Date
- May 2010
- Posts
- 5
- Rep Power
- 0
Well the code is being executed in that main, in the same class (see my reply), I am using JavaSE 1.6 in my eclipse
- 05-31-2010, 09:19 PM #10
Have you tried it at a command prompt, not in eclipse?
- 05-31-2010, 10:24 PM #11
Member
- Join Date
- May 2010
- Posts
- 4
- Rep Power
- 0
code
Please try this code :
public static boolean comparePasswords(String input) throws IOException
{
FileReader reader = new FileReader("src/password.spm");
StringBuffer buffer = new StringBuffer();
BufferedReader passwordBuffer = new BufferedReader(reader);
String line = null;
while ((line = passwordBuffer.readLine()) != null)
buffer.append(line);
return encrypt(input).equals(buffer.toString());
}
- 06-02-2010, 12:45 PM #12
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 06-02-2010, 03:12 PM #13
To remove any special paths used by IDE. If everything is in the same folder for testing it removes one source of confusion
- 06-02-2010, 05:06 PM #14
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Hmmm, that's interesting. So we can boil done those path issues. But at the same time, I think that in most of the IDEs we can specify relative paths as well as absolute paths.
- 06-02-2010, 05:15 PM #15
I like to keep it simple (only one folder) until I've fixed the other problems. Then add code for allow for using other folders.
- 06-03-2010, 07:18 AM #16
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
In most of the cases, what I'm doing is that keep all resources (files, images, etc..) in a single folder and use the hard corded values. Later I'm worried about the structuring them.
Similar Threads
-
How can I save so the all my closed methods remain closed when exiting?
By Addez in forum EclipseReplies: 1Last Post: 01-31-2010, 03:17 AM -
standard input stream storing to a generic method?
By vendetta in forum New To JavaReplies: 3Last Post: 01-29-2010, 08:13 PM -
classloader
By vijayabaskar in forum Advanced JavaReplies: 8Last Post: 04-06-2009, 08:08 AM -
ClassLoader and JVM
By Pradeen in forum New To JavaReplies: 0Last Post: 01-19-2009, 06:04 PM -
java.lang.NumberFormatException: For input stream:jav
By osval in forum New To JavaReplies: 2Last Post: 08-07-2007, 03:50 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks