G
GsT
Gast
Hi!
Ich habe nun mit der Java Properties Klasse gearbeitet - Allerdings weiß ich nicht, wie ich die Properties quasi speichern soll.
Selbst wenn ich per Hand Iwas=iwasanderes in die Date ischreibe, benutzt er das was ich per Code gesettet habe.. Obwohl er das nur benutzen soll, wenn nichts anderes vorhanden ist.
Zweites Problem:
Sollte bei Fehlern eigentlich einen String ausgeben - Gibt aber stattdessen eine Fehlermeldung, immer wenn es timeout ist.
Ich habe nun mit der Java Properties Klasse gearbeitet - Allerdings weiß ich nicht, wie ich die Properties quasi speichern soll.
Java:
File f = new File("Config.properties");
public void load(){
try {
p.load(new FileInputStream(f));
} catch (FileNotFoundException e) {
try {
f.createNewFile();
p.load(new FileInputStream(f));
} catch (IOException e1) {}
} catch (IOException e) {
e.printStackTrace();
}
p.setProperty("Iwas", "iwas");
Iwas = p.getProperty("Iwas");
}
Zweites Problem:
Java:
public static void downloadFile(String url_str, OutputStream os) throws IllegalStateException, MalformedURLException, ProtocolException, IOException {
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) {
System.out.println(Prop.download.replaceAll("%name", url_str));
byte tmp_buffer[] = new byte[4096];
InputStream is = conn.getInputStream();
int n;
while ((n = is.read(tmp_buffer)) > 0) {
os.write(tmp_buffer, 0, n);
os.flush();
}
} else {
System.out.println(Prop.DL_ERR.replaceAll("%name", url_str).replaceAll("%html_response", "" + responseCode));
}
}