Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: offline explorer(how save images , css files ,js files?)

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Thanked 0 Times in 0 Posts

    Question offline explorer(how save images , css files ,js files?)

    Hello my dear friends.
    i want to write a offline explorer program with java.
    i save url html code that user typed.(output.txt)
    now how to sava images and css files and java scripts file?[Without the use of htmlparse class]
    Thanks.(output.txt seve in C:\Users\fh\Documents\NetBeansProjects\offline explorer\output.txt)

    public static void main(String[] args) throws MalformedURLException, IOException {
    String urlString;
    if (args.length == 1)
    	 urlString = args[0];
    else {
    	 System.out.println("Enter URL:");
    	 Scanner s = new Scanner(System.in);
    	 urlString = s.next();
    	 System.out.println("Using " + urlString);
    URL u = new URL(urlString);
    URLConnection connection = u.openConnection();
    HttpURLConnection httpConnection = (HttpURLConnection) connection;
    int code = httpConnection.getResponseCode();
    String message = httpConnection.getResponseMessage();
    System.out.println(code + " " + message);
    if (code != HttpURLConnection.HTTP_OK)
    InputStream instream = connection.getInputStream();
    Scanner in = new Scanner(instream);
    PrintWriter out = new PrintWriter("output.txt");
    while (in.hasNextLine())
    	 String input = in.nextLine();
    Last edited by pbrockway2; December 27th, 2012 at 03:44 PM. Reason: code tags added

  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Thanked 206 Times in 182 Posts

    Default Re: offline explorer(how save images , css files ,js files?)

    Hi mark92, welcome to the forums!

    When you post code, please use "code" tags. Put [code] at the start of the code, and [/code] at the end: that way the code will be formatted and readable when it appears on a web page.


    Is there some reason why you don't use some code to properly parse the returned page content? Any robust alternative would seem to involve a lot of reading of the specifications for html/css/js and even then you would have to contend with the nonstandard content all over teh internet.

    But, if you want to hack about with the returned text - and this *is* a reasonable exercise in using regex and the Java String methods - then you have already been given a good answer at codecall.net. (download the file, parse out the links with regex and/or indexOf(), and download their content) Your best bet would be to engage with the poster in that other thread and *ask* about anything that is unclear.

    If, in any case, you want to have the discussion in multiple places then it is only polite to provide links at each site to the others so that everybody taking part in the discussion knows what else is being said. Bear in mind that many people will not respond to cross posts for fear of wasting their time contributing to something that has been dealt with elsewhere.

    Also at codecall.net

Similar Threads

  1. Replies: 3
    Last Post: August 3rd, 2012, 10:40 AM
  2. Replies: 2
    Last Post: February 24th, 2012, 07:56 PM
  3. [SOLVED] files size for files inside the JAR file
    By Natherul in forum Java Theory & Questions
    Replies: 3
    Last Post: February 9th, 2012, 03:17 PM
  4. Seraching through files in a folder for a pattern match inside the files.
    By dazzabiggs in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 2nd, 2011, 08:35 AM
  5. Replies: 1
    Last Post: March 22nd, 2011, 06:59 PM