Results 1 to 7 of 7
Thread: Console in NetBeans
- 12-28-2009, 07:44 PM #1
Member
- Join Date
- Dec 2009
- Posts
- 8
- Rep Power
- 0
Console in NetBeans
Hello,
I'm using NetBeans 6.7.1 and trying to use this piece of code:
Console c = System.console();
if (c == null) {
System.err.println("No console.");
System.exit(1);
}
String str = c.readLine("Enter line: ");
to read a line from the console, but I always get null for the console. It seems that the io.Console cannot be used from NetBeams.
I also found this in the class doc (java.sun.com/javase/6/docs/api/java/io/Console.html):
"Whether a virtual machine has a console is dependent upon the underlying platform and also upon the manner in which the virtual machine is invoked. If the virtual machine is started from an interactive command line without redirecting the standard input and output streams then its console will exist and will typically be connected to the keyboard and display from which the virtual machine was launched. If the virtual machine is started automatically, for example by a background job scheduler, then it will typically not have a console. "
It seems that it has somenting to do with how the JVM was started, but I run the file from a command line an it works perfectly...
Is there any way to use this Console from NetBeans?
Anaconda.
- 12-29-2009, 12:11 AM #2
Personally, I hate the console class for the problems you specified; I avoid it. Also, it breaks compatibility with java 1.5 which is still popular!
Someone might have a brilliant and simple solution for your problem, but personally I would just avoid using it. As far as I know, Console doesn't do anything that can't be done without Console. Good luck!
- 12-29-2009, 02:10 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Did you read the documentation? Do you have the idea what's the meaning of Console?
On IDE you cannot see the console, because IDE use it's own panel. Write your code in a text file and run it accordingly. Yes, as quad64bit said, Console class is a mess.
- 12-29-2009, 08:25 PM #4
Member
- Join Date
- Dec 2009
- Posts
- 8
- Rep Power
- 0
Of curse the program runs fine from the command line, the trick would be to use it in NetBeans...
Yes, NetBeans has its own panel, and you can use it in this way to read a line:
InputStreamReader inputStreamReader = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(inputStreamReader);
System.out.println("Type the line:");
String line = reader.readLine();
However, it would be nice to use the other way. The question that I am asking is not clear from the documentation I found. I guess that's why I am asking it in this forum....
Eranga, could you be more specific? Do you mean that the NetBean panel cannot be used as a console, as specified in the console definition? Do you know the reason?
- 12-30-2009, 07:47 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 12-30-2009, 03:56 PM #6
Member
- Join Date
- Dec 2009
- Posts
- 8
- Rep Power
- 0
It works, but still cannot use the System.console to read lines...
- 12-31-2009, 02:14 AM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
It works means you can see the console/ command prompt isn't it? When you run the code from the IDE, each IDEs have there own console to execute the code. IDE is not execute external applications. I guess it's much better.
Use of System.console is another thing. As quad64bit says console gives lots of pros/cons. Can you show your code here.
Similar Threads
-
How Do You?? Get the Console Output as a GUI??
By Lyricid in forum AWT / SwingReplies: 10Last Post: 11-20-2009, 11:35 PM -
how to take input from console in jsp
By veena in forum New To JavaReplies: 1Last Post: 05-06-2008, 04:39 AM -
ModSecurity Console 1.0.3
By Java Tip in forum Java SoftwareReplies: 0Last Post: 04-15-2008, 06:44 PM -
Console doesn't appear!
By PeteMarsh in forum New To JavaReplies: 2Last Post: 12-17-2007, 05:41 PM -
Help with java console
By carl in forum New To JavaReplies: 1Last Post: 08-06-2007, 02:44 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks