aspose file tools*
The moose likes Beginning Java and the fly likes end of file indicator for more than one file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "end of file indicator for more than one file " Watch "end of file indicator for more than one file " New topic
Author

end of file indicator for more than one file

Slawomir Wieczorek
Greenhorn

Joined: Dec 07, 2011
Posts: 20

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

Joined: May 29, 2005
Posts: 479
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

Joined: Oct 13, 2005
Posts: 38818
    
  23
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: end of file indicator for more than one file