Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 13th, 2013, 12:23 PM
cubocik cubocik is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 14 cubocik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 31 m 30 sec
Reputation Power: 0
Webpage saver ...

Hey im kind new in this , but I have coded this but It doesn't work...

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

public class webpagesaver{
public static void main(String[] args) throws IOException{
URLConnection conn = url.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
String saveFile = "PaginaCopiada.html"; //name of SaveFile
String location = "ht#t#p://ww#w.#sa#p#o.com"; // website url withou #
URL url = new URL(location);
BufferedWriter out = new BufferedWriter(new FileWriter(saveFile));
BufferedReader in = new BufferedReader(new InputStreamReader(is));
String l = out.readLine();
while(l!=null){
out.write(l);
out.newLine();
}
in.close();
out.close();

}
}
The objective is : Put website link and Save all the page..

May you help me ?

Reply With Quote
  #2  
Old January 13th, 2013, 03:59 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,955 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 53 m 34 sec
Reputation Power: 345
Quote:
It doesn't work...

Can you explain what "doesn't work" means?
If you get error messages, please copy the full text and paste it here.
If the program executes but the results are unexpected, please show what it does and explain.

Please edit your post and wrap the code in code tags to preserve formatting.

Reply With Quote
  #3  
Old January 13th, 2013, 04:32 PM
cubocik cubocik is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 14 cubocik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 31 m 30 sec
Reputation Power: 0
Code:
 
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

public class webpagesaver{
public static void main(String[] args) throws IOException{


String saveFile = "PaginaCopiada.html"; //name of SaveFile
String location = "http://www.sapo.pt"; // website url withou #
URL url = new URL(location);
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream();
conn.connect();
BufferedWriter out = new BufferedWriter(new FileWriter(saveFile));
BufferedReader in = new BufferedReader(new InputStreamReader(is));
String l = out.readLine();
while(l!=null){
out.write(l);
out.newLine();
}
in.close();
out.close();

}
}


Compiling messages

Code:
URLConnection conn = url.openConnection();
^
  symbol:   class URLConnection
  location: class webpagesaver
webpagesaver.java:19: error: cannot find symbol
InputStream is = conn.getInputStream();
^
  symbol:   class InputStream
  location: class webpagesaver
webpagesaver.java:23: error: cannot find symbol
String l = out.readLine();
              ^
  symbol:   method readLine()
  location: variable out of type BufferedWriter
3 errors

Reply With Quote
  #4  
Old January 13th, 2013, 05:20 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,955 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 53 m 34 sec
Reputation Power: 345
Check that there are import statements for the classes referenced in the error messages.

The code needs formatting. Logically nested statements should be indented 3-4 spaces and not start in the first column.

Reply With Quote
  #5  
Old January 14th, 2013, 10:27 AM
cubocik cubocik is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 14 cubocik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 31 m 30 sec
Reputation Power: 0
But the idea is that ? Im on the right way ?

Reply With Quote
  #6  
Old January 14th, 2013, 10:54 AM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,955 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 53 m 34 sec
Reputation Power: 345
Does the code compile and execute now? It needs to have a clean compile before it can be executed and tested.

It is hard to read and understand unformatted code.

Reply With Quote
  #7  
Old January 14th, 2013, 11:41 AM
cubocik cubocik is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 14 cubocik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 31 m 30 sec
Reputation Power: 0
Ty, I checked and corrected

Code:
import java.io.*;
import java.net.*;
 
public class webpagesaver{
    public static void main(String[] args) throws IOException{
    
        String saveFile = "PaginaCopiada.html"; //name of SaveFile
        String location = "http://www.iol.pt"; // website url withou #
        URL url = new URL(location);
        URLConnection conn = url.openConnection();
        InputStream is = conn.getInputStream();
        conn.connect();
        BufferedWriter out = new BufferedWriter(new FileWriter(saveFile));
        BufferedReader in = new BufferedReader(new InputStreamReader(is));
        String l = in.readLine();
        while(l!=null){
            out.write(l);
            out.newLine();
        }
        in.close();
        out.close();
    }    
}


But with that page it works well but for example with facebook it save a blank page, and another example with www.iol.pt its doesn't stop running and I stopped and checked that it created a 1,5Gb its normal ?

Reply With Quote
  #8  
Old January 14th, 2013, 12:05 PM
stdunbar's Avatar
stdunbar stdunbar is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: May 2004
Location: Superior, CO, USA
Posts: 2,398 stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 18 h 14 m 16 sec
Reputation Power: 1660
Send a message via Yahoo to stdunbar Send a message via Google Talk to stdunbar
How do you read the line from the server? Now how do you read the next line? Hint - debugging 101 might have been to look at the output and realize that you're outputting the same line over and over.
__________________
Need Java help? Want to help people who do? Sit down with a cup of Java at the hotjoe forums.

Reply With Quote
  #9  
Old January 14th, 2013, 12:24 PM
cubocik cubocik is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 14 cubocik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 31 m 30 sec
Reputation Power: 0
I dont know , I never work with URL api

Reply With Quote
  #10  
Old January 14th, 2013, 01:24 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,955 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 53 m 34 sec
Reputation Power: 345
Quote:
I never work with URL api

The problem has nothing to do with the source of the input. The code would have the same problem if it was reading from a disk file.

Change this line:
Code:
 InputStream is = conn.getInputStream();

to this:

 InputStream is = new FileInputStream("<PUT FILENAME HERE>");

compile and execute the code to see what happens.
Replace <PUT FILENAME HERE> with the name of a file on your PC

Last edited by NormR : January 14th, 2013 at 01:28 PM.

Reply With Quote
  #11  
Old January 14th, 2013, 02:44 PM
cubocik cubocik is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 14 cubocik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 31 m 30 sec
Reputation Power: 0
The file with the link website ?

Reply With Quote
  #12  
Old January 14th, 2013, 02:57 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,955 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 53 m 34 sec
Reputation Power: 345
The test I suggested has nothing to do with the web or any website.
It was to show you that the problem with the code has nothing to do with the internet.
The problem will be the same if you try to read a file from your PC.

Reply With Quote
  #13  
Old January 14th, 2013, 03:10 PM
cubocik cubocik is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 14 cubocik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 31 m 30 sec
Reputation Power: 0
Ty for the answer I did this

Code:
import java.io.*;
import java.net.*;
 
public class webpagesaver{
    public static void main(String[] args) throws IOException{
    
        String saveFile = "PaginaCopiada.html"; //name of SaveFile
        String location = "http://www.iol.pt"; // website url withou #
        URL url = new URL(location);
        URLConnection conn = url.openConnection();
        InputStream is = new FileInputStream("um.txt"); //conn.getInputStream();
        conn.connect();
        BufferedWriter out = new BufferedWriter(new FileWriter(saveFile));
        BufferedReader in = new BufferedReader(new InputStreamReader(is));
        String l = in.readLine();
        while(l!=null){
            out.write(l);
            out.newLine();
        }
        in.close();
        out.close();
    }    
}


But happens the same

Reply With Quote
  #14  
Old January 14th, 2013, 03:22 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,955 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 53 m 34 sec
Reputation Power: 345
Yes that is what was supposed to happen. That shows you that the problem is in your program and has nothing to do with the internet.

Did you look in the file that was written?
The problem was explained by stdunbar in post#8.

Where does the code read the next record from the file? It needs to do that inside the loop.

Reply With Quote
  #15  
Old January 14th, 2013, 04:15 PM
cubocik cubocik is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 14 cubocik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 31 m 30 sec
Reputation Power: 0
Code:
import java.io.*;
import java.net.*;
 
public class webpagesaver{
    public static void main(String[] args) throws IOException{
    
        String saveFile = "PaginaCopiada.html"; //name of SaveFile
        String location = "http://www.iol.pt"; // website url withou #
        URL url = new URL(location);
        URLConnection conn = url.openConnection();
        InputStream is = conn.getInputStream();
        conn.connect();
        BufferedWriter out = new BufferedWriter(new FileWriter(saveFile));
        BufferedReader in = new BufferedReader(new InputStreamReader(is));
        String l = in.readLine();
        while(l!=null){
            out.write(l);
            out.newLine();
            in.next(); //<-- this ?
        }
        in.close();
        out.close();
    }    
}

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Webpage saver ...

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap