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? |
Code:
DataInputStream in = new DataInputStream(new BufferedInputStream(System.in)); |
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. |
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. |
To read characters from a file, try:
Code:
BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(file)));; |
All times are GMT -5. The time now is 06:10 AM. |