Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Webpage saver -- help

Webpage saver -- help

Scheduled Pinned Locked Moved Java
csharpjavahtmlhelpquestion
11 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cubocik
    wrote on last edited by
    #1

    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 = "http://www.sapo.pt"; //ask website 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 ?

    L 1 Reply Last reply
    0
    • C cubocik

      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 = "http://www.sapo.pt"; //ask website 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 ?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      cubocik wrote:

      It doesn't work...

      Please do not assume that people can guess what this means; explain what happens, what results or errors you see etc. Also please use <pre> tags around your code so it is properly formatted.

      One of these days I'm going to think of a really clever signature.

      C 1 Reply Last reply
      0
      • L Lost User

        cubocik wrote:

        It doesn't work...

        Please do not assume that people can guess what this means; explain what happens, what results or errors you see etc. Also please use <pre> tags around your code so it is properly formatted.

        One of these days I'm going to think of a really clever signature.

        C Offline
        C Offline
        cubocik
        wrote on last edited by
        #3

        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

        Edit/Delete Message

        L 1 Reply Last reply
        0
        • C cubocik

          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

          Edit/Delete Message

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          You are missing a few #import statements, and you are also trying to read from your output stream. Try this:

          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.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 = in.readLine();
              while(l!=null){
                  out.write(l);
                  out.newLine();
              }
              in.close();
              out.close();
          }    
          

          }

          One of these days I'm going to think of a really clever signature.

          C 1 Reply Last reply
          0
          • L Lost User

            You are missing a few #import statements, and you are also trying to read from your output stream. Try this:

            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.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 = in.readLine();
                while(l!=null){
                    out.write(l);
                    out.newLine();
                }
                in.close();
                out.close();
            }    
            

            }

            One of these days I'm going to think of a really clever signature.

            C Offline
            C Offline
            cubocik
            wrote on last edited by
            #5

            Im nice , ty thats work but.. for only this site , im trying for example facebook and its save a blank page

            C L 2 Replies Last reply
            0
            • C cubocik

              Im nice , ty thats work but.. for only this site , im trying for example facebook and its save a blank page

              C Offline
              C Offline
              cubocik
              wrote on last edited by
              #6

              Another I checked now with iol.pt , and when it was running its never finish running and when I control+C it it created a 1,5Gb

              1 Reply Last reply
              0
              • C cubocik

                Im nice , ty thats work but.. for only this site , im trying for example facebook and its save a blank page

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                You need to use your debugger to see what gets returned in the InputStream.

                One of these days I'm going to think of a really clever signature.

                C 1 Reply Last reply
                0
                • L Lost User

                  You need to use your debugger to see what gets returned in the InputStream.

                  One of these days I'm going to think of a really clever signature.

                  C Offline
                  C Offline
                  cubocik
                  wrote on last edited by
                  #8

                  what debugger you advice?

                  L 1 Reply Last reply
                  0
                  • C cubocik

                    what debugger you advice?

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    Whichever one you have available. If you are using eclipse or Netbeans then they both include built in visual debuggers. If you are using command line tools then jdb. You can find lots of useful information on Java in general starting at the Java Tutorials[^].

                    One of these days I'm going to think of a really clever signature.

                    C 1 Reply Last reply
                    0
                    • L Lost User

                      Whichever one you have available. If you are using eclipse or Netbeans then they both include built in visual debuggers. If you are using command line tools then jdb. You can find lots of useful information on Java in general starting at the Java Tutorials[^].

                      One of these days I'm going to think of a really clever signature.

                      C Offline
                      C Offline
                      cubocik
                      wrote on last edited by
                      #10

                      Thanks for the answer I just forgot the line l=in.nextLine(); If not the program will read infinite time the first Line lol, Thanks !!!!

                      L 1 Reply Last reply
                      0
                      • C cubocik

                        Thanks for the answer I just forgot the line l=in.nextLine(); If not the program will read infinite time the first Line lol, Thanks !!!!

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #11

                        That's OK, so did I. :doh:

                        One of these days I'm going to think of a really clever signature.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups