Java code to implement "wget" to save a web page in linux
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Java code to implement "wget" to save a web page in linux
This is the code i used, there is no error in execution but no file is bein saved in the working directory.
I'm new in java,so just started learning.
if some one can help me out with this wil be really great
Thanx in advance
public class Hel
{
public static void main(String args[])
throws IOException
{
try
{
Process q = Runtime.getRuntime().exec("export http_proxy='http://it06106036:it06106036@172.16.0.254:8080'");
Process p = Runtime.getRuntime().exec(" wget -U MyBrowser/1.0 http://59.165.190.44/exams/results1/btechNEW/BT55displayNEW.php?regno=mkageit026&Submit=Submit");
BufferedReader r= new BufferedReader(new InputStreamReader(q.getInputStream())); //juz added this to call the constructors
r.readLine();
BufferedReader s= new BufferedReader(new InputStreamReader(p.getInputStream()));
s.readLine();
}catch(IOException ioe)
{
System.exit(1);
}
public class Hel
{
public static void main(String args[])
throws IOException
{
try
{
String cmd = "ls -al";
Runtime run = Runtime.getRuntime();
Process pr = run.exec(cmd);
pr.waitFor();
BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line = "";
while ((line=buf.readLine())!=null) {
System.out.println(line);}
}catch(IOException ioe)
{
System.exit(1);
}
}
}
i tried to just implement ls command....
and during that when i compile i get the following error.I have added try and catch but still iam gettin unhandled exception .plz help
Station71:~/RESA/wget# javac Hel.java
----------
1. ERROR in Hel.java (at line 25)
pr.waitFor();
^^^^^^^^^^^^
Unhandled exception type InterruptedException
----------
when i removed pr.waitFor(),it worked just fine.
thank you
Quote:
Originally Posted by Kakarot_Rathish
import java.io.*;
import java.io.IOException;
public class Hel
{
public static void main(String args[])
throws IOException
{
try
{
String cmd = "ls -al";
Runtime run = Runtime.getRuntime();
Process pr = run.exec(cmd);
pr.waitFor();
BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line = "";
while ((line=buf.readLine())!=null) {
System.out.println(line);}
}catch(IOException ioe)
{
System.exit(1);
}
}
}
i tried to just implement ls command....
and during that when i compile i get the following error.I have added try and catch but still iam gettin unhandled exception .plz help
Station71:~/RESA/wget# javac Hel.java
----------
1. ERROR in Hel.java (at line 25)
pr.waitFor();
^^^^^^^^^^^^
Unhandled exception type InterruptedException
----------
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.