Hello!!!
Can someone help me?
I want to open a url in the default browser....But I never found how to do this...Can someone give me a step by step guide?! :crying:
Sorry for the silly question,but I'm really new in java...
Any help is highly appreciated!
Thanks advice!
P.s I need it to work just on windows OS.
5 replies to this topic
#1
Posted 31 December 2011 - 06:46 AM
|
|
|
#2
Posted 31 December 2011 - 08:39 AM
Desktop (Java Platform SE 7 )
This class will make life easier for you.
First, make sure the Desktop object is supported by calling the appropriate method from the Desktop class.
After this, call the browse method for your desktop object. As your browse parameter, pass a string of the URL you wish to open.
This class will make life easier for you.
First, make sure the Desktop object is supported by calling the appropriate method from the Desktop class.
After this, call the browse method for your desktop object. As your browse parameter, pass a string of the URL you wish to open.
#3
Posted 11 January 2012 - 09:37 AM
Hmmm I have made this class:
The problem is that the above class can open just 1 url...Is there a way to get a list of urls from a text area,or from a file? - There will be 1 url per line...
Someone who can give me an advice? I'm really new in java...
Thanks for any replay!
public class Open {
public static void URL(String url) {
try {
Runtime.getRuntime().exec("rundll32 url.dll, FileProtocolHandler " + url);
} catch (IOException e) {
}
}
public static void main(String[] args) {
Open.URL("http://google.com");
}
}
The problem is that the above class can open just 1 url...Is there a way to get a list of urls from a text area,or from a file? - There will be 1 url per line...
Someone who can give me an advice? I'm really new in java...
Thanks for any replay!
#4
Posted 11 January 2012 - 10:22 AM
#5
Posted 11 January 2012 - 10:51 AM
But how can I read it line by line...I never found the proper commands..I have made the same programm in c++ (without GUI),but in java the way to read a file seems kinda confusing for me.... :(
#6
Posted 11 January 2012 - 08:39 PM
The simplest way would be to set up a Scanner object and use the .nextLine() method to consume the file line by line.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









