public static void main(String[] args) throws MalformedURLException,
IOException {
URLConnection urlconAktie = new URL("http://www.java-forum.org")
.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(
urlconAktie.getInputStream()));
FileWriter writer = new FileWriter(new File(System
.getProperty("user.home")
+ System.getProperty("file.separator") + "Java Forum"));
while (reader.ready()) {
writer.write(reader.read());
}
writer.close();
}
private void getFile(String strURL) {
InputStream inStream = null;
OutputStream outStream = null;
URLConnection urlCon = null;
Integer intWritten = null;
Integer intRead = null;
ProgressMonitor proMonitor = new ProgressMonitor(mainFrame,
"Lade...", "", 0, 100);
try {
outStream = new BufferedOutputStream(new FileOutputStream(new File(
System.getProperty("user.home") + "/")));
urlCon = new URL(strURL).openConnection();
inStream = urlCon.getInputStream();
proMonitor.setMaximum(urlCon.getContentLength());
final byte[] buffer = new byte[1024];
final InputStream inStreamFinal = inStream;
final OutputStream outStreamFinal = outStream;
final Integer intReadFinal = intRead;
final Integer intWrittenFinal = intWritten;
final ProgressMonitor proMonitorFinal = null;
new Thread(new Runnable() {
public void run() {
try {
while ((intReadFinal = inStreamFinal.read(buffer)) != -1) {
try {
outStreamFinal.write(buffer, 0, intReadFinal);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
intWrittenFinal += intReadFinal;
proMonitorFinal.setProgress(intWrittenFinal);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}