InputStream not working?
Here's my code.
import java.net.URL;
import java.net.URLConnection;
import java.net.MalformedURLException;
import java.io.File;
import java.io.InputStream;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
publicclass Test
{
URL pageURL;
public Test(URL page)
{
pageURL = page;
}
publicvoid saveFile(File f)
{
Scanner in;
BufferedWriter out;
try
{
in =new Scanner(getStream(pageURL));
out =new BufferedWriter(new FileWriter(f));
while(in.hasNextLine())
{
out.write(in.nextLine());
}
in.close();
out.close();
}
catch(IOException e)
{
e.printStackTrace();
return;
}
}
public InputStream getStream(URL page)throws IOException
{
URLConnection conn = page.openConnection();
return conn.getInputStream();
}
publicstaticvoid main(String[] args)
{
//Scanner s = new Scanner(System.in);
URL url;
try
{
url =new URL(javax.swing.JOptionPane.showInputDialog(null,"Enter in a URL","URL:"));
}
catch(MalformedURLException e)
{
e.printStackTrace();
return;
}
Test saver =new Test(url);
saver.saveFile(new File("C:\\Test.html"));
}
}
The resulting file does not render the same way as if I just opened the page with Firefox. Does anyone know why this is? I didn't check line for line, but the file look to be the same as the source of the page.

