• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to input End of File indicator

 
Ranch Hand
Posts: 215
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I read in a book that end of file could be given as input for a program. For Windows, it's <Ctrl> + Z.
But it never works.

This is the code i tried to work on:



Please let me know if I need to post the full program.
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That looks like something out of chapter 14 of the Deitel book.

C:\JavaPrograms\DeitelCh14>edit Eipe.java

C:\JavaPrograms\DeitelCh14>javac Eipe.java

C:\JavaPrograms\DeitelCh14>java Eipe
Campbell
Campbell
Ritchie
Ritchie
^Z

C:\JavaPrograms\DeitelCh14>

You see I am, unusually, running Windows, and the program turned off when I used ctrl-Z. Please provide more details about what goes wrong.
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm running it from NetBeans IDE. Is that the reason, it doesn't work?

John Eipe
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried it from command line and it works! What should I do in Net Beans?

John Eipe
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't know, I am afraid.
 
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have worked on Netbeans

See, Editors like netbeans have an inbuild prompt that emulate the command prompt of the OS,
However, these should not be seens as a benchmark for your system.
usually editors now a days have limited support for text input via thier console.

if you do want to have an interactive user input in a CUI interface,
run the program via the os command prompt.

The problem is that now a days CUI is obsolete, you can prepare a GUI in a matter of seconds that does the same job in a more pleasing way.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that Eclipse allows this magic to happen
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had the same problem. I use intellij Idea. someone told me that Intellij use linux shell so you must End via ctrl + d not ctrl +z. His advice solved the problem.
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Yes, ctrl‑D is the end of file indicator for Linux/Unix/etc., but it is usually a bad idea to use it at the terminal because you are risking closing System.in. Don't therefore use while (myScanner.hasNext() ... for System.in because that will behave like an infinite loop.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Eipe wrote:I read in a book that end of file could be given as input for a program. For Windows, it's  <Ctrl> + Z.
But it never works.


Hmmm, what about using your own terminator?

It's a bit retro (1960's-retro to be exact), but it still does the job and it saves the Ctrl-D/Z problem that Campbell mentioned.
Just pick a string which should never appear in real life, and have your program terminate when it receives it.

FYI: "classic" terminators for punched-card decks were things like '$$$$' or 'ZZZZ' - which may well be where Ctrl-Z came from. :-)

HIH

Winston

Oops - Just realised this is a 9 year old thread. My apologies. :-)
 
reply
    Bookmark Topic Watch Topic
  • New Topic