AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



computer-file-handling: Copy file to each available drive


- - i want to copy file to each available drive
in this i also want to copy file to each available drive with setting attributes as
system and hidden (make it system file and hidden)
-- also want to pre-check the available drive for writing( is it read only or secured or writable)
-- i also want to know how to handle file handling or file manipulation related exceptions.

computer x 5
file-handling x 9
Posted On : 2017-05-08 13:04:24.0
profile rahul patil - anyforum.in rahul patil
42-30
up-rate
5
down-rate

Answers


Please refer below code snippet, You can do something like this in your requirement. But You can´t write in C:/ Drive till you run your java code as administrative.

SystemDrives.java:
-------------------------------------------------------
package in.anyforum;

import java.io.File;
import java.io.IOException;

import javax.swing.filechooser.FileSystemView;

public class SystemDrives {
public static void main(String[] args) {
File[] drives=displayAllSystemDrivesWithPermissions();
writingHiddenFileToDrives(drives);
}
public static File[] displayAllSystemDrivesWithPermissions(){
File[] roots = File.listRoots();
for(int i = 0; i < roots.length ; i++)
System.out.println(roots[i]+" | "+FileSystemView.getFileSystemView().getSystemDisplayName(roots[i])+" | CAN READ? "+roots[i].canRead()+" | CAN Write?"+roots[i].canWrite());
return roots;
}

public static void writingHiddenFileToDrives(File[] drives){
try{
for(File file:drives){
file=new File(file.getPath()+"MyHiddenFile.java");
boolean status=file.createNewFile();
setHiddenProperty(file);
System.out.println(status?"Written":"Something went wring");
}
}catch (Exception e) {
System.out.println(e);
}
}

public static void setHiddenProperty(File file) throws InterruptedException, IOException {
Runtime.getRuntime().exec("attrib +H "+file.getPath());
}

}

Posted On : 2017-05-09 23:43:20
Satisfied : 1 Yes  0 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523188249150
Reply This Thread
up-rate
4
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in