Salve
Da giorni sto cercando di scaricare un file da indirizzo URL, premetto che il file lo scarica, ma vorrei che l'utente decida dove il file deve essere salvato, tipo un esplora risorse.
Sto usando "JFileChooser" ma no mi salva nulla.
Dove sbaglio?
Vi posto il codice :
codice:
import java.io.File;
import java.io.FileOutputStream;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import javax.swing.JFileChooser;
public class scarica {
public static void main(String[] args) {
try {
String file = ("A020202.zip");
URL website = new URL ("http://gis.sitgeo.it/Mappe/CREMIA/"+file);
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(file);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
JFileChooser fileChooser = new JFileChooser();
if (fileChooser.showSaveDialog(fileChooser)==JFileChooser.APPROVE_OPTION){
File file2 = fileChooser.getCurrentDirectory();
System.out.println("il file è"+file2.getAbsolutePath());
}
}
catch (Exception e){
System.err.println(e);
}
}
}
Grazie in anticipo.