我正在尝试使用其url将java.util.properties中的属性添加到联机文件中。
这是我目前掌握的代码:
public static boolean savePropertiesToURL(Properties properties, String link, String fileName) {
boolean result = false;
if (properties != null && link != null && fileName != null) {
try {
URL url = new URL(link);
try {
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
try {
OutputStream outStream = connection.getOutputStream();
try {
properties.store(outStream, fileName);
} catch (IOException ex) {
System.err.println("Unable to store the properties: " + ex.getMessage());
} finally {
try {
outStream.flush();
result = true;
} catch (IOException ex) {
Logger.getLogger(PropertiesUtil.class.getName()).log(Level.SEVERE, null, ex);
System.err.println("Unable to flush outputstream: " + ex.getMessage());
}
outStream.close();
}
} catch (IOException ex) {
System.err.println("Unable to get outputstream: " + ex.getMessage());
}
} catch (IOException ex) {
System.err.println("Unable to open URL connexion: " + ex.getMessage());
}
} catch (MalformedURLException ex) {
System.err.println("The URL hasn't been created: " + ex.getMessage());
}
}
return result;
}
它经历了这一切,并返回真实。即使文件没有写。每次捕获都有记录者,但从未触发任何捕获。
暂无答案!
目前还没有任何答案,快来回答吧!