public class FileDemo {
public static void main(String[] args) {
File f = null;
boolean bool = false;
try {
// returns pathnames for files and directory
f = new File("C:/Texts/TutorialsPoint/Java");
// create directories
bool = f.mkdirs();
// print
System.out.print("Directory created? "+bool);
} catch(Exception e) {
// if any error occurs
e.printStackTrace();
}
}
}
public class FileMkdirsExample {
public static void main(String[] args) {
// initialize File object
File file = new File("C:\\javatutorialhq\\test_folder\\input\\test1");
// check if the pathname already exists
// if not create it
if(!file.exists()){
// create the full path name
boolean result = file.mkdirs();
if(result){
System.out.println("Successfully created "+file.getAbsolutePath());
}
else{
System.out.println("Failed creating "+file.getAbsolutePath());
}
}else{
System.out.println("Pathname already exists");
}
}
}
public class GFG {
public static void main(String args[])
{
// create an abstract pathname (File object)
File f = new File("F:\\program");
// check if the directory can be created
// using the abstract path name
if (f.mkdirs()) {
// display that the directory is created
// as the function returned true
System.out.println("Directory is created");
}
else {
// display that the directory cannot be created
// as the function returned false
System.out.println("Directory cannot be created");
}
}
}
public class FileExample {
public static void main(String[] args) throws Exception {
try {
File folder = new File("C:\sandbox\testFolder\sub1\sub2");
if (!folder.exists()) {
if (folder.mkdirs()) {
System.out.println("Folders created!");
} else {
System.out.println("Failed to create folders!");
}
} else {
System.out.println("Folder already exists!");
}
} catch (Exception e) {
System.err.println("Things went wrong: " + e.getMessage());
e.printStackTrace();
} finally {
}
}
}
public class JavaCreateMultipleDirectoriesExample {
public static void main(String[] args) {
// the folders "000/111/222" don't exist initially
File dir = new File("/Users/al/tmp/000/111/222");
// create multiple directories at one time
boolean successful = dir.mkdirs();
if (successful) {
// created the directories successfully
System.out.println("directories were created successfully");
} else {
// something failed trying to create the directories
System.out.println("failed trying to create the directories");
}
}
}
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent.getBooleanExtra(PAUSE_DOWNLOAD, false)) {
queue.pause();
return START_REDELIVER_INTENT;
}
VideoDownLoadInfo video = (VideoDownLoadInfo) intent.getSerializableExtra(VIDEOS_INFO);
EventBus.getDefault().postSticky(video,EventBusTags.CACHE_DOWNLOAD_BEGIN);
videos.put(video.getId()+"",video);
File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Sunny_Videos");
if (!dir.exists()) {
dir.mkdirs();
}
DaoMaster master = GreenDaoHelper.getInstance().create(video.getDbName()).getMaster();
master.newSession().startAsyncSession().insertOrReplace(video);
File file = new File(dir.getAbsolutePath(), video.getId() + ".mp4");
BaseDownloadTask task = (FileDownloader.getImpl().create(video.getVideo().getPlayUrl()).setPath(file.getAbsolutePath()).setTag(video.getId()+""));
task.setListener(new CommonDownloadListener());
queue.enqueue(task);
if (isInit){
queue.resume();
isInit = false;
}
return START_NOT_STICKY;
}
private void extract(BasicImageReader reader, String name,
ImageLocation location) throws IOException, BadArgs {
File directory = new File(options.directory);
byte[] bytes = reader.getResource(location);
File resource = new File(directory, name);
File parent = resource.getParentFile();
if (parent.exists()) {
if (!parent.isDirectory()) {
throw TASK_HELPER.newBadArgs("err.cannot.create.dir",
parent.getAbsolutePath());
}
} else if (!parent.mkdirs()) {
throw TASK_HELPER.newBadArgs("err.cannot.create.dir",
parent.getAbsolutePath());
}
if (!ImageResourcesTree.isTreeInfoResource(name)) {
Files.write(resource.toPath(), bytes);
}
}
private File createFile() {
String dir = Environment.getExternalStorageDirectory() + "/winter/monitor";
File dirFile = new File(dir);
if (!dirFile.exists()) {
dirFile.mkdirs();
}
SimpleDateFormat dateformat1 = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.CHINESE);
String a1 = dateformat1.format(new Date());
File file = new File(dir + "/" + a1 + ".log");
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
return file;
}
public void testDynamicRegionFactoryDiskDir() throws CacheException {
CacheCreation cache = new CacheCreation();
File f = new File("diskDir");
f.mkdirs();
cache.setDynamicRegionFactoryConfig(new DynamicRegionFactory.Config(f, null, true, true));
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
cache.createRegion("root", attrs);
// note that testXml can't check if they are same because enabling
// dynamic regions causes a meta region to be produced.
testXml(cache, false);
assertEquals(true, DynamicRegionFactory.get().isOpen());
assertEquals(f.getAbsoluteFile(), DynamicRegionFactory.get().getConfig().getDiskDir());
Region dr = getCache().getRegion("__DynamicRegions");
if (dr != null) {
dr.localDestroyRegion();
}
}
protected void writeStaticNodesFile(String enodes) {
try {
File dir = new File(this.reactContext
.getFilesDir() + STATIC_NODES_FILES_PATH);
if (dir.exists() == false) dir.mkdirs();
File f = new File(dir, STATIC_NODES_FILES_NAME);
if (f.exists() == false) {
if (f.createNewFile() == true) {
WritableArray staticNodes = new WritableNativeArray();
staticNodes.pushString(enodes);
Writer output = new BufferedWriter(new FileWriter(f));
output.write(staticNodes.toString());
output.close();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}