Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Android file delete
In the below mentioned code I am writing dummy data to all files present in external storage and renaming to "abc.txt". But what I want is to write dummy data to only that file which I select and rename that particular file. How do I do?
 
File[] files = root.listFiles();
for ( File f : files ) {
if (f.isDirectory())
continue;
FileChannel rwChannel = new RandomAccessFile(f, "rw").getChannel();
int numBytes = (int)rwChannel.size();
ByteBuffer buffer = rwChannel.map(FileChannel.MapMode.READ_WRITE, 0, numBytes);
System.out.println("buffer"+buffer);
byte[] randomBytes = new byte[numBytes];
new Random().nextBytes(randomBytes);
buffer.put(randomBytes);
rwChannel.write(buffer);
rwChannel.close();
}
File root1 = android.os.Environment.getExternalStorageDirectory();
File[] files1 = root.listFiles();
for ( File f : files ) {
if (f.isDirectory())
continue;
File myFile1 = new File(root,"abc.txt");
f.renameTo(myFile1);
}
Posted 4-Jun-13 19:55pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 5 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100