Changeset 2038 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2009-09-03T15:08:25+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Preferences.java
r2017 r2038 13 13 import java.io.OutputStreamWriter; 14 14 import java.io.PrintWriter; 15 import java.nio.channels.FileChannel; 15 16 import java.util.ArrayList; 16 17 import java.util.Arrays; … … 44 45 45 46 /** 46 * Internal storage for the preference ddirectory.47 * Internal storage for the preference directory. 47 48 * Do not access this variable directly! 48 49 * @see #getPreferencesDirFile() … … 291 292 try { 292 293 setSystemProperties(); 294 String prefFile = getPreferencesDir() + "preferences"; 295 296 // Backup old preferences 297 copyFile(new File(prefFile), new File(prefFile + "_backup")); 298 293 299 final PrintWriter out = new PrintWriter(new OutputStreamWriter( 294 new FileOutputStream( getPreferencesDir() + "preferences"), "utf-8"), false);300 new FileOutputStream(prefFile + "_tmp"), "utf-8"), false); 295 301 for (final Entry<String, String> e : properties.entrySet()) { 296 302 String s = defaults.get(e.getKey()); … … 301 307 } 302 308 out.close(); 309 310 File tmpFile = new File(prefFile + "_tmp"); 311 copyFile(tmpFile, new File(prefFile)); 312 tmpFile.delete(); 313 303 314 } catch (final IOException e) { 304 315 e.printStackTrace(); … … 307 318 } 308 319 } 320 321 /** 322 * Simple file copy function that will overwrite the target file 323 * Taken from http://www.rgagnon.com/javadetails/java-0064.html (CC-NC-BY-SA) 324 * @param in 325 * @param out 326 * @throws IOException 327 */ 328 public static void copyFile(File in, File out) throws IOException { 329 FileChannel inChannel = new FileInputStream(in).getChannel(); 330 FileChannel outChannel = new FileOutputStream(out).getChannel(); 331 try { 332 inChannel.transferTo(0, inChannel.size(), 333 outChannel); 334 } 335 catch (IOException e) { 336 throw e; 337 } 338 finally { 339 if (inChannel != null) { 340 inChannel.close(); 341 } 342 if (outChannel != null) { 343 outChannel.close(); 344 } 345 } 346 } 347 309 348 310 349 public void load() throws IOException {
Note:
See TracChangeset
for help on using the changeset viewer.