Guest User

Untitled

a guest
Jul 17th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. public boolean ObjectToFile(String fileName, Object obj){
  2. boolean success = false;
  3. FileOutputStream fos = null;
  4. ObjectOutputStream out = null;
  5. try{
  6. File dir = GetAppDir();
  7. if(dir != null){
  8. fos = new FileOutputStream(dir + "/" + fileName);
  9. out = new ObjectOutputStream(fos);
  10. out.writeObject(obj);
  11. out.close();
  12. success = true;
  13. }
  14. }catch(Exception e){}
  15. return success;
  16. }
  17.  
  18. public Object FileToObject(String fileName){
  19. Object obj = null;
  20. try{
  21. File dir = GetAppDir();
  22. if(dir != null){
  23. File f = new File(dir, fileName);
  24. if(f.exists() && f.isFile()){
  25. FileInputStream fis = null;
  26. ObjectInputStream in = null;
  27. fis = new FileInputStream(f);
  28. in = new ObjectInputStream(fis);
  29. obj = in.readObject();
  30. in.close();
  31. }
  32. }
  33. }catch(Exception e){}
  34. return obj;
  35. }
Add Comment
Please, Sign In to add comment