Results 1 to 2 of 2
Thread: Text and ASCII Code I/O
- 03-04-2011, 05:46 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 56
- Rep Power
- 0
Text and ASCII Code I/O
I am writing a program for a "Magic Eight Ball" that will read in the answers from a text file. I can get single digit numbers' ASCII code to read in, but how would I read in a "10" for example?
Thanks!
AB
Java Code:import java.io.*; class MagicBall { public static void main(String[] args) throws IOException { FileReader inputStream = null; FileWriter outputStream = null; try { inputStream = new FileReader("answers.txt"); outputStream = new FileWriter("done.txt"); int c; boolean done = false; while(((c = inputStream.read()) != -1) && !done) { if(c == 55) { while((c = inputStream.read()) != -1) { outputStream.write(c); if(c == 46) { break; } } done = true; } } } finally { if (inputStream != null) { inputStream.close(); } if (outputStream != null) { outputStream.close(); } } } }
- 03-04-2011, 06:24 PM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Similar Threads
-
ASCII to binary code
By Vagabond.drv in forum New To JavaReplies: 12Last Post: 01-13-2011, 01:52 PM -
Changing text colour in code
By dbashby in forum New To JavaReplies: 2Last Post: 04-29-2009, 03:32 PM -
a simple code (cldc or midp) to write a text file ouside of the application package
By sina in forum CLDC and MIDPReplies: 3Last Post: 12-12-2008, 12:12 PM -
Ascii code.........
By Somitesh Chakraborty in forum New To JavaReplies: 6Last Post: 11-04-2008, 05:32 PM -
How to obtain ASCII code of a character
By karma in forum New To JavaReplies: 4Last Post: 07-20-2008, 02:57 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks