Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900