CopyPastor

Detecting plagiarism made easy.

Score: 0.8144879937171936; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2019-01-19
by Tarasantan

Original Post

Original - Posted on 2015-01-13
by Afzal Ahmad



            
Present in both answers; Present only in the new answer; Present only in the old answer;

This answer is not mine,I am just providing it to help.
SharedPreferences preferences=this.getSharedPreferences("com.example.application", Context.MODE_PRIVATE); Map<String,?> keys = preferences.getAll(); Properties properties = new Properties(); for(Map.Entry<String,?> entry : keys.entrySet()){ String key = entry.getKey(); String value = entry.getValue().toString(); properties.setProperty(key, value); } try { File file = new File("externalPreferences.xml"); FileOutputStream fileOut = new FileOutputStream(file); properties.storeToXML(fileOut, "External Preferences"); fileOut.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
and to retrive use this,
try { File file = new File("externalPreferences.xml"); FileInputStream fileInput = new FileInputStream(file); Properties properties = new Properties(); properties.loadFromXML(fileInput); fileInput.close();
Enumeration enuKeys = properties.keys(); SharedPreferences.Editor editor = preferences.edit(); while (enuKeys.hasMoreElements()) { String key = (String) enuKeys.nextElement(); String value = properties.getProperty(key); editor.putString(key, value); editor.commit(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
NOTE You can handle only String type preferences with this code,
Use this code,
SharedPreferences preferences=this.getSharedPreferences("com.example.application", Context.MODE_PRIVATE); Map<String,?> keys = preferences.getAll(); Properties properties = new Properties(); for(Map.Entry<String,?> entry : keys.entrySet()){ String key = entry.getKey(); String value = entry.getValue().toString(); properties.setProperty(key, value); } try { File file = new File("externalPreferences.xml"); FileOutputStream fileOut = new FileOutputStream(file); properties.storeToXML(fileOut, "External Preferences"); fileOut.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }

and to retrive use this,
try { File file = new File("externalPreferences.xml"); FileInputStream fileInput = new FileInputStream(file); Properties properties = new Properties(); properties.loadFromXML(fileInput); fileInput.close(); Enumeration enuKeys = properties.keys(); SharedPreferences.Editor editor = preferences.edit(); while (enuKeys.hasMoreElements()) { String key = (String) enuKeys.nextElement(); String value = properties.getProperty(key); editor.putString(key, value); editor.commit(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
**NOTE** You can handle only String type preferences with this code,

        
Present in both answers; Present only in the new answer; Present only in the old answer;