I wanted to download a webpage. I confirmed that this code works. But I'm not sure whether I'm doing it neatly. Would you review my (full) code?
import java.io.IOException;
import java.io.InputStream;
import java.io.FileOutputStream;
import java.net.URL;
public class GetHTML {
private InputStream in;
private FileOutputStream out;
private String articleName;
public void setArticleName(String articleName) {
this.articleName = articleName;
}
public void download(URL url) throws IOException {
in = url.openStream();
out = new FileOutputStream(articleName + ".html");
byte[] arr = new byte[1024];
while(true) {
int count = in.read(arr);
if(count == -1) { break; }
out.write(arr, 0, count);
}
in.close();
out.close();
}
public static void main(String[] args) throws IOException {
String site1 = "http://codereview.stackexchange.com/questions/";
String site2 = "69";
String site3 = "is-this-implementation-of-shamos-hoey-algorithm-ok";
URL url = new URL(site1 + site2 + "/" + site3);
GetHTML getHTML = new GetHTML();
getHTML.setArticleName("[" + site2 + "]" + site3);
getHTML.download(url);
}
}