• 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 read value from console ??

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i want to read some value from console..could someone pls gimme one example ??
tx
Oni
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
assuming that you want to read input from the dos prompt.
You can use the BufferedReader class in java.io
Here is a small peace of code which may help.
This is to read one line from the input.
BufferedReader br = new BuferedReader(new InputStreamReader (System.in));
System.out.println("Enter name");
String name=br.readLine();
This may help
Thanks
 
Oni Anand
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks lot
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
//This application might help you.
// Java code to read console input from a Microsoft DOS command line
import java.io.*;
public class ReadConsole {
public static void main(String args[]) throws IOException {
// declare your InputStream and OutputStream objects
InputStream inStream;
OutputStream outStream;
int inChar;
// assign System.in to inStream and System.out to outStream
inStream = System.in;
outStream = System.out;
System.out.println("Reads input from console ... Ctrl+Z to quit.");
System.out.println("After Ctrl+Z, writes console input on monitor .... ");
// read (that is, execute the loop)
// from console until end-of-file (Ctrl+Z)
try {
while ( ( inChar = inStream.read() ) != -1 ) {
outStream.write( inChar );
}
}
// catch block to handle IOException:
catch ( IOException ioe ) {
System.out.println( "Error: " + ioe.getMessage() );
}
// ensure that streams are closed
// irregardless of whether an IOException occurs
finally {
inStream.close();
outStream.close();
}
}
}
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might want to explore JOptionPane in javax.swing.*
Also, David Eck at hws.edu provides a file called TextIO that is an excellent set of both input and output routines. Everyone I've used works great.
 
reply
    Bookmark Topic Watch Topic
  • New Topic