File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

end of file indicator for more than one file

 
Slawomir Wieczorek
Greenhorn
Posts: 20
Eclipse IDE Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I've got a class to write down two files (user is choosing which one to write):



Now when testing it like that:


the terminal output in my Eclipse goes:

To terminate input, type the end-of-file indicator
when you are prompted to enter input.
On UNIX/Linux/Mac OS X type <ctrl> d then press Enter
On Windows type <ctrl> z then press Enter

Enter account number (> 0), first name, last name and balance.
? 100 Alan Jones 348,17
Enter account number (>0), first name, last name and balance.
? <- Here is where I put CTRL + Z to switch to another loop ->

To terminate input, type the end-of-file indicator
when you are prompted to enter input.
On UNIX/Linux/Mac OS X type <ctrl> d then press Enter
On Windows type <ctrl> z then press Enter

Enter account number (> 0) and transaction amount.
?


When pressing Ctrl+Z after the first file is done, it's closing the whole application. Why? What do I don't understand here?
 
Ralph Cook
Ranch Hand
Posts: 479
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm wondering if your console's status is still end-of-file, so at the start of your input loop you test for end of file, and the second time through it is already true.

You could test this by putting a breakpoint on that test, and stepping from there.

rc
 
Campbell Ritchie
Sheriff
Pie
Posts: 47222
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You do not usually need to call flush() before close(). Your != null check as written will fail, and you might suffer a null exception. You should consider whether to have the output variable as a local variable rather than as a field.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic