|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: Aug 2008
Messaggi: 210
|
[Java] Problema con scrittura File
Salve a tutti. Sto cercando di creare un programma che scarica una pagina web e la salve in una determinata cartella nel computer.
Allora, riesco a procurarmi il sorgente della pagina, ma ho un problema durante la scrittura... ecco il metodo interessato: Codice:
public void saveHTML (URL url, File location) throws Exception
{
String title = url.getFile();
String output = explore (url);
File file = new File (location, title);
Formatter writer = new Formatter (file);
writer.format ("%s", output);
}
Quando però mando in esecuzione, viene lanciata questa eccezione: Codice:
java.io.FileNotFoundException: /home/utente/Desktop (Is a directory)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
at java.util.Formatter.<init>(Formatter.java:2025)
at WebExplorer.saveHTML(WebExplorer.java:50)
at WebExplorer.<init>(WebExplorer.java:14)
at WebExplorer.main(WebExplorer.java:56)
|
|
|
|
|
|
#2 | |
|
Senior Member
Iscritto dal: Jul 2006
Città: Bergamo
Messaggi: 401
|
A naso direi che non hai messo anche il nome del file dopo la path:
Quote:
Ciauz
__________________
iMac 27" 5K |
|
|
|
|
|
|
#3 |
|
Member
Iscritto dal: Aug 2008
Messaggi: 210
|
Il problema era che "www.google.com" in effetti non ha un file, dato che nell'indirizzo c'è solo appunto un indirizzo e non una pagina. Quindi ho risolto così:
Codice PHP:
|
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Nov 2005
Città: Texas
Messaggi: 1722
|
Hai provato poi a chiudere il Formatter? (i.e. writer.close())
__________________
In God we trust; all others bring data |
|
|
|
|
|
#5 |
|
Member
Iscritto dal: Aug 2008
Messaggi: 210
|
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 07:13.



















