mohammad1992 Posted December 21, 2012 Share Posted December 21, 2012 (edited) 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?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) return; InputStream instream = connection.getInputStream(); Scanner in = new Scanner(instream); PrintWriter out = new PrintWriter("output.txt"); while (in.hasNextLine()) { String input = in.nextLine(); out.println(input); System.out.println(input); } out.close(); Edited December 21, 2012 by mohammad1992 Link to comment Share on other sites More sharing options...
thescientist Posted December 25, 2012 Share Posted December 25, 2012 what's your problem? Are you getting any errors? Link to comment Share on other sites More sharing options...
mohammad1992 Posted December 28, 2012 Author Share Posted December 28, 2012 i want know how download images, css files ? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now