LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 01-12-2005, 01:36 AM   #1
greg108
Member
 
Registered: Aug 2003
Location: CA USA
Distribution: FC2, FC4, Mandrake 10, Slackware 10, RedHat 9, Suse 9.1, College Linux, Debian Sarge, Gentoo
Posts: 170

Rep: Reputation: 30
java - reading from stdin


I know how to read a String from standart input this way:
Something like:

inStr = reader. readLine(); //reader is a BufferedReader type

and then if I want just one character:

myChar = inStr.charAt(0);

and if I want double:

myDouble = Double. parseDouble(inStr);

But how can I read one character (of char type) or a double without those conversions?
 
Old 01-12-2005, 03:28 AM   #2
csfalcon
Member
 
Registered: Jun 2004
Location: MD
Distribution: Fedora Core
Posts: 269

Rep: Reputation: 31
Code:
DataInputStream in = new DataInputStream(new BufferedInputStream(System.in));
		
	try
	{
		in.readChar();
		in.readDouble();
	}
	catch (IOException ioe)
	{
	}

Last edited by csfalcon; 01-12-2005 at 03:50 AM.
 
Old 01-12-2005, 03:59 PM   #3
greg108
Member
 
Registered: Aug 2003
Location: CA USA
Distribution: FC2, FC4, Mandrake 10, Slackware 10, RedHat 9, Suse 9.1, College Linux, Debian Sarge, Gentoo
Posts: 170

Original Poster
Rep: Reputation: 30
Thanks, but when I do this and print the character that I just entered then the output is not a character but a bunch of digits (some kind of binary stream)

I need to read a character and test it with a switch statement.

Last edited by greg108; 01-12-2005 at 04:05 PM.
 
Old 01-13-2005, 03:34 PM   #4
csfalcon
Member
 
Registered: Jun 2004
Location: MD
Distribution: Fedora Core
Posts: 269

Rep: Reputation: 31
hmm, sorry about that. Seems like readDouble() reads in IEEE representation of double and readChar() read in unicode? Not sure...

But looks like you would have to read it as a string first and parse out the different components.
 
Old 01-13-2005, 04:29 PM   #5
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,523

Rep: Reputation: 365Reputation: 365Reputation: 365Reputation: 365
To read characters from a file, try:
Code:
    BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(file)));;
    int i;
    while((i=br.read())!=-1)
    {
      char c=(char)i;
      ...;
    }
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving a text file as a variable and reading it every second in java script mrobertson Programming 4 03-26-2007 09:25 PM
unbuffered stdin Mike Davies Linux - Software 1 03-03-2006 01:13 AM
java: reading secure website ashirazi Programming 2 11-09-2004 12:26 PM
stdin and NUL. How ? Mike Davies Linux - Software 5 10-28-2004 08:06 AM
Java - Reading /dev/mouse - appears to be empty chakkerz Linux - Hardware 1 08-19-2004 08:48 PM


All times are GMT -5. The time now is 08:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration