Guest User

Untitled

a guest
Apr 25th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. try
  2. {
  3. new RandomAccessFile(file,"rw").setLength(0);
  4. }
  5. catch (FileNotFoundException e1)
  6. {
  7. // TODO Auto-generated catch block
  8. Log.i("Exception caught ==> ", e1.toString());
  9. e1.printStackTrace();
  10. }
  11. catch (IOException e)
  12. {
  13. // TODO Auto-generated catch block
  14. Log.i("Exception caught ==> ", e.toString());
  15. e.printStackTrace();
  16. }
  17.  
  18. RandomAccessFile ram = null;
  19. byte[] mydata = null;
  20. try
  21. {
  22. System.out.println("...rrunning my app...");
  23. String str =Environment.getExternalStorageDirectory().getAbsolutePath()+"/myfile.txt";
  24. // File f = new File(str);
  25. ram =new RandomAccessFile(str,"rw");
  26. ram.setLength(0);
  27. ram.write("i am fine".getBytes());
  28. System.out.println("...file length..."+ram.length());
  29. mydata = new byte[(int) ram.length()];
  30. ram.close();
  31. RandomAccessFile ram1 =new RandomAccessFile(str,"rw");
  32. ram1.read(mydata);
  33. System.out.println("...data present in 11file..."+new String(mydata));
  34.  
  35. }
  36. catch (Exception e1)
  37. {
  38. // TODO Auto-generated catch block
  39. Log.i("Exception caught ==> ", e1.toString());
  40. e1.printStackTrace();
  41. }
  42.  
  43. try (FileOutputStream fos = new FileOutputStream("xxx")) {
  44. fos.write(new byte[0]);
  45. }
  46.  
  47. try (FileWriter fw = new FileWriter("xxx")) {
  48. fw.write("");
  49. }
Add Comment
Please, Sign In to add comment