Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    14
    Rep 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();
                l=in.readLine(); //<-- this ?
            }
            in.close();
            out.close();
        }    
    }
    Is that ?
  2. #17
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    What happens when you compile and execute the program? Does it give errors?
    Does it do what you want? If not, please explain what it does.
  4. #18
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    14
    Rep Power
    0
    It compile successful and copy ... now I replace the file input ?
  6. #19
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    14
    Rep Power
    0
    Im trying for eg with facebook and it only appear a blank page
  8. #20
  9. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    What is the contents of the file that the program writes?

    Not all websites return a response to a user's simple program.
  10. #21
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    14
    Rep Power
    0
    doesn't write anything ...

    produce a empty file ..


    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.facebook.com"; // website url withou #
            URL url = new URL(location);
            URLConnection conn = url.openConnection();
            InputStream is = conn.getInputStream();// new FileInputStream("um.txt"); 
            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();
    	    l=in.readLine();
            }
            in.close();
            out.close();
        }    
    }
  12. #22
  13. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    Not all websites return a response to a user's simple program.
  14. #23
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    14
    Rep Power
    0
    How do I make an arg in java for example to execute do this..
    java program arg1 arg1
  16. #24
  17. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    That looks like the command line that would be typed in a console window to execute the class named program and to pass it two args: arg1 and arg1
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo