Results 1 to 10 of 10
- 01-30-2013, 03:44 PM #1
Member
- Join Date
- Jan 2013
- Posts
- 6
- Rep Power
- 0
HELP: Exception in thread "main" java.io.IOException: Stream closed
Hi Guys, i'm new in java programming can someone help me to fix this exception,but whenever i compile my program it has no errors, the error always happen after the loop saying
Exception in thread "main" java.io.IOException: Stream closed
at sun.nio.cs.StreamDecoder.ensureOpen(StreamDecoder. java:46)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:1 47)
at java.io.InputStreamReader.read(InputStreamReader.j ava:184)
at java.io.BufferedReader.fill(BufferedReader.java:15 4)
at java.io.BufferedReader.readLine(BufferedReader.jav a:317)
at java.io.BufferedReader.readLine(BufferedReader.jav a:382)
at StudentInfo2.main(StudentInfo2.java:26)
Thanks In Advance :DJava Code:import java.io.*; import java.util.Scanner; public class StudentInfo2 { public static void main(String[] args)throws IOException, FileNotFoundException { Scanner scan = new Scanner(System.in); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String input = "", studN="", add="", contact=""; int choose; char buffer1[] = new char[input.length()]; char buffer2[] = new char[studN.length()]; char buffer3[] = new char[add.length()]; char buffer4[] = new char[contact.length()]; FileWriter fw = new FileWriter("file1.txt"); do { System.out.println("Choose (1): Record Data \n (2): View Data \n (3): EXIT"); choose = scan.nextInt(); if(choose==1) { System.out.print("Student No: "); studN = br.readLine(); System.out.print("Name: "); input = br.readLine(); System.out.print("Address: "); add = br.readLine(); System.out.print("Contact #: "); contact = br.readLine(); System.out.println(); for(int i=0; i<=buffer1.length; i+=1) { fw.write(buffer1); fw.write(buffer2); fw.write(buffer3); fw.write(buffer4); } fw.close(); { FileWriter f2 = new FileWriter("C:/Users/MAX BALLENA/desktop/stud_info.txt"); f2.write("\r\nStudent Number: "+studN); f2.write("\r\nName: "+input); f2.write("\r\nAddress: "+add); f2.write("\r\nContact Number: "+contact); f2.close(); } } else if (choose==2) { FileReader fr = new FileReader("C:/Users/MAX BALLENA/Desktop/stud_info.txt"); br = new BufferedReader(fr); while((input = br.readLine())!= null) { System.out.println(input); } fr.close(); } } while(choose !=3); } }Last edited by ChrisChan; 01-30-2013 at 05:11 PM.
- 01-30-2013, 03:55 PM #2
Re: HELP: Exception in thread "main" java.io.IOException: Stream closed
When posting code, please use the code tags to preserve formatting.
When do you close the stream?How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 01-30-2013, 04:04 PM #3
Member
- Join Date
- Jan 2013
- Posts
- 6
- Rep Power
- 0
- 01-30-2013, 04:23 PM #4
Re: HELP: Exception in thread "main" java.io.IOException: Stream closed
Are you sure? That error seems to suggest otherwise. I can't really read unformatted code though, so the best I can do is suggest you step through this with a debugger, or at least add some print statements to figure out what's going on.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 01-30-2013, 04:48 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,471
- Rep Power
- 16
Re: HELP: Exception in thread "main" java.io.IOException: Stream closed
You can edit your original post to enclose the code in [code] tags [/code].
That way we might actually be able to read it.Please do not ask for code as refusal often offends.
- 01-30-2013, 04:55 PM #6
Member
- Join Date
- Jan 2013
- Posts
- 6
- Rep Power
- 0
- 01-30-2013, 05:04 PM #7
Re: HELP: Exception in thread "main" java.io.IOException: Stream closed
Then you should have read the FAQ before posting, which contains information on how to do all of these things:
Reading and Posting Messages
BB Code List - Java Programming Forum - Learn Java ProgrammingHow to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 01-30-2013, 05:09 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,471
- Rep Power
- 16
- 01-30-2013, 05:12 PM #9
Member
- Join Date
- Jan 2013
- Posts
- 6
- Rep Power
- 0
- 01-30-2013, 06:17 PM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,471
- Rep Power
- 16
Re: HELP: Exception in thread "main" java.io.IOException: Stream closed
Can you provide a run through that gives the error?
That is what the user inputs?
I can see at least one route through where the stream used by 'br' is closed and the loop goes back round with a closed reader (user selects '2' then '1').
It's hard to tell because your indentation is all over the place.Please do not ask for code as refusal often offends.
Similar Threads
-
Error: "Exception in thread "main" java.util.NoSuchElementException"
By Mattiscool in forum New To JavaReplies: 1Last Post: 11-02-2012, 11:38 PM -
"Exception in thread "main" java.lang.NoSuchMethodError: main"
By isnkumar in forum New To JavaReplies: 2Last Post: 06-20-2012, 12:18 AM -
Got struck with this :- " Exception in thread "main" java.lang.NullPointerException"
By Vermont in forum New To JavaReplies: 5Last Post: 12-21-2011, 06:44 PM -
Exception in thread "main" java.lang.NumberFormatException:input string: "060320
By renu in forum New To JavaReplies: 14Last Post: 04-08-2011, 06:01 PM -
Question about error "Exception in thread "main" java.lang.NoSuchMethodError: main
By ferdzz in forum New To JavaReplies: 5Last Post: 06-22-2010, 03:51 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks