Download Problem

Status
Nicht offen für weitere Antworten.

Developer_X

Top Contributor
HI, mit einem FileChooser nur für Directories suche ich mir einen Ordner(Desktop) und dann will ich eine Datei mit dieser Methode in diesen Ordner(Desktop) downloaden. Geht aber leider nicht, wieso?
Weil diese exception kommt, mir wird der zugriff verweigert:
Methode:
[JAVA=77]
public void downloadFile(String url_str, String s) throws IllegalStateException, MalformedURLException,ProtocolException, IOException
{
FileOutputStream fos = new FileOutputStream(s);

URL url = new URL(url_str.replace(" ", "%20"));

HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.connect();

int responseCode = conn.getResponseCode();

if (responseCode == HttpURLConnection.HTTP_OK)
{
byte _tmp_buffer[] = new byte[4096];

InputStream _is = conn.getInputStream();
@SuppressWarnings("unused")
int _n;
int data = 0;

while ((_n = _is.read(_tmp_buffer)) > 0)
{
data++;
}

this.data = data;

byte tmp_buffer[] = new byte[4096];

InputStream is = conn.getInputStream();
int n;

while ((n = is.read(tmp_buffer)) > 0)
{
prozessWindow.repaint();
prozess++;
fos.write(tmp_buffer, 0, n);
fos.flush();
}
fos.close();

JOptionPane.showMessageDialog(prozessWindow, sp.getString(6));
}
else
{
throw new IllegalStateException("HTTP response: " + responseCode);
}
}
[/code]

Exception:
Code:
java.io.FileNotFoundException: C:\Users\Kevin Riehl\Desktop (Zugriff verweigert)
	at java.io.FileOutputStream.open(Native Method)
	at java.io.FileOutputStream.<init>(Unknown Source)
	at java.io.FileOutputStream.<init>(Unknown Source)
	at downloader.Downloader.downloadFile(Downloader.java:79)
	at downloader.Downloader$1.run(Downloader.java:61)

M.f.G. developer_x
 
Anscheinen stimmt der Pfad zu deinem Desktop nicht. Ich weiß jetzt nich ob du ihn genau in deinem Code angegeben hast, wenn ja dann versuch es mal so:
Java:
String homePath = System.getProperty("user.home");
String desktopPath += "/Desktop";
 
Das hat nichts mit falschem Pfad zu tun. Die Fehlermeldung sagt halt alles. "Zugriff verweigert" heißt genau was es sagt.
 
Status
Nicht offen für weitere Antworten.

Neue Themen


Zurück
Oben