Skip to content

Instantly share code, notes, and snippets.

@nik-joseph
Last active March 11, 2017 18:57
Show Gist options
  • Save nik-joseph/bbcb0f2288e2f296591221ea0c9b2538 to your computer and use it in GitHub Desktop.
Save nik-joseph/bbcb0f2288e2f296591221ea0c9b2538 to your computer and use it in GitHub Desktop.
sourcetext
import java.net.*;
import java.io.*;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Scanner;
import java.io.Writer;
public class hi
{
public static void main(String args[])
{
URL url;
System.out.println("Script Begin....\n");
InputStream is = null;
BufferedReader br;
String line;
Scanner input = new Scanner(System.in);
System.out.println("Enter the url\n");
String s = input.nextLine();
try
{
System.out.println("Creating source file\n");
String filename= "Source.html";
System.out.println("Source file created\n");
FileWriter fw=new FileWriter(filename,false);//if true will append the new data
try
{
url = new URL(s);
is = url.openStream(); // throws an IOException
br = new BufferedReader(new InputStreamReader(is));
while ((line = br.readLine()) != null)
{
System.out.println("Transfering data\n");
fw.write(line);//write the string to the file
}
System.out.println("Data Transfer done...\n");
} catch (MalformedURLException mue)
{
mue.printStackTrace();
} catch (IOException ioe)
{
ioe.printStackTrace();
} finally
{
try
{
if (is != null) is.close();
} catch (IOException ioe)
{
// nothing to see here
}
}
fw.close();
}
catch(IOException ioe)
{
System.err.println("IOException:" + ioe.getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment