RSS Forums RSS
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 2943 | Replies: 2 | Solved | Thread Tools  Display Modes
Reply
Join Date: Sep 2007
Posts: 36
Reputation: Webbsta is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
Webbsta Webbsta is offline Offline
Light Poster

Reading from console input

  #1  
Jan 30th, 2008
I'm getting further and further to figuring out how my java program can read from my console application written in vb.net, i have some of my class here that i found on a site:

This is mainly to do with reading numbers from input but il change it later.
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.text.DecimalFormat;
  5. import java.text.ParseException;
  6.  
  7. public class InputHandler{
  8. public static void main(String[] args) {
  9. System.out.println("Reading from console.");
  10. double numberFromConsole;
  11. try {
  12. InputStreamReader isr = new InputStreamReader(System.in);
  13. BufferedReader br = new BufferedReader(isr);
  14. String s = br.readLine();
  15. DecimalFormat df = new DecimalFormat();
  16. Number n = df.parse(s);
  17. numberFromConsole = n.doubleValue();
  18. } catch (IOException e) {
  19. numberFromConsole = 0;
  20. } catch (ParseException e) {
  21. numberFromConsole = 0;
  22. }
  23. System.out.println(numberFromConsole );
  24. }
  25. }
This reads input from my console application but how do i call it from my main process so that the user can type away into the console and the java program picks up the input and then puts it into a string.

I know if this seems basic but I'm really not that good with java, I'm mainly used to programming in vb, vb.net and C#.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2007
Location: Greece
Posts: 763
Reputation: javaAddict has a spectacular aura about javaAddict has a spectacular aura about javaAddict has a spectacular aura about 
Rep Power: 5
Solved Threads: 101
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Master Poster

Re: Reading from console input

  #2  
Jan 31st, 2008
Compile it, I think if you are console the command is >javac InputHandler.java (if I remember correctly because for a very long time I have been using IDEs) and run it with the command
>java InputHandler
Then the program will print the message in your code and then just insert the input.
I AM the 12th CYLON
Reply With Quote  
Join Date: Sep 2007
Posts: 36
Reputation: Webbsta is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
Webbsta Webbsta is offline Offline
Light Poster

Re: Reading from console input

  #3  
Feb 1st, 2008
Thank you soooo much, i can now do input into my java program woohoo thanks allot! this is going to allow me to do so much more then i used to be able to do.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the Java Forum
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 7:46 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC