• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

end of file indicator for more than one file

 
Greenhorn
Posts: 20
Eclipse IDE Java Ubuntu
  • 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?
 
Ranch Hand
Posts: 479
  • 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
 
Marshal
Posts: 69416
276
  • 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.
 
She's out of the country right now, toppling an unauthorized dictatorship. Please leave a message with this tiny ad:
Try Free Java/.NET Libraries for Word Excel PowerPoint and PDF
htttp://www.e-iceblue.com/free-apis.html
    Bookmark Topic Watch Topic
  • New Topic