Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try
- {
- new RandomAccessFile(file,"rw").setLength(0);
- }
- catch (FileNotFoundException e1)
- {
- // TODO Auto-generated catch block
- Log.i("Exception caught ==> ", e1.toString());
- e1.printStackTrace();
- }
- catch (IOException e)
- {
- // TODO Auto-generated catch block
- Log.i("Exception caught ==> ", e.toString());
- e.printStackTrace();
- }
- RandomAccessFile ram = null;
- byte[] mydata = null;
- try
- {
- System.out.println("...rrunning my app...");
- String str =Environment.getExternalStorageDirectory().getAbsolutePath()+"/myfile.txt";
- // File f = new File(str);
- ram =new RandomAccessFile(str,"rw");
- ram.setLength(0);
- ram.write("i am fine".getBytes());
- System.out.println("...file length..."+ram.length());
- mydata = new byte[(int) ram.length()];
- ram.close();
- RandomAccessFile ram1 =new RandomAccessFile(str,"rw");
- ram1.read(mydata);
- System.out.println("...data present in 11file..."+new String(mydata));
- }
- catch (Exception e1)
- {
- // TODO Auto-generated catch block
- Log.i("Exception caught ==> ", e1.toString());
- e1.printStackTrace();
- }
- try (FileOutputStream fos = new FileOutputStream("xxx")) {
- fos.write(new byte[0]);
- }
- try (FileWriter fw = new FileWriter("xxx")) {
- fw.write("");
- }
Add Comment
Please, Sign In to add comment