本文整理汇总了Java中java.io.File.mkdirs方法的典型用法代码示例。如果您正苦于以下问题:Java File.mkdirs方法的具体用法?Java File.mkdirs怎么用?Java File.mkdirs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.File
的用法示例。
在下文中一共展示了File.mkdirs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onStartCommand
import java.io.File; //导入方法依赖的package包/类
@Override
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;
}
示例2: extract
import java.io.File; //导入方法依赖的package包/类
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);
}
}
示例3: createFile
import java.io.File; //导入方法依赖的package包/类
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;
}
示例4: testDynamicRegionFactoryDiskDir
import java.io.File; //导入方法依赖的package包/类
/**
* @since GemFire 4.3
*/
@Test
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();
}
}
示例5: writeStaticNodesFile
import java.io.File; //导入方法依赖的package包/类
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();
}
}
示例6: getExternalCacheDir
import java.io.File; //导入方法依赖的package包/类
private static File getExternalCacheDir(Context context, String name) {
File dataDir = new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data");
File appCacheDir = new File(new File(dataDir, context.getPackageName()), "name");
if (!appCacheDir.exists()) {
if (!appCacheDir.mkdirs()) {
return null;
}
try {
(new File(appCacheDir, ".nomedia")).createNewFile();
} catch (IOException var4) {
}
}
return appCacheDir;
}
示例7: testFormatWithNonInteractive
import java.io.File; //导入方法依赖的package包/类
/**
* Test namenode format with -format -nonInteractive options when a non empty
* name directory exists. Format should not succeed.
*
* @throws IOException
*/
@Test
public void testFormatWithNonInteractive() throws IOException {
// we check for a non empty dir, so create a child path
File data = new File(hdfsDir, "file");
if (!data.mkdirs()) {
fail("Failed to create dir " + data.getPath());
}
String[] argv = { "-format", "-nonInteractive" };
try {
NameNode.createNameNode(argv, config);
fail("createNameNode() did not call System.exit()");
} catch (ExitException e) {
assertEquals("Format should have been aborted with exit code 1", 1,
e.status);
}
// check if the version file does not exists.
File version = new File(hdfsDir, "current/VERSION");
assertFalse("Check version should not exist", version.exists());
}
示例8: setupConfigDir
import java.io.File; //导入方法依赖的package包/类
public static void setupConfigDir(File globalDir)
{
configDir = new File(globalDir, WorldBorder.MODID);
if ( !configDir.exists() && configDir.mkdirs() )
Log.info("Created config directory for the first time");
}
示例9: testShellCommandProcess
import java.io.File; //导入方法依赖的package包/类
@org.junit.Test
public void testShellCommandProcess() throws Exception {
NativeProcessBuilder npb = NativeProcessBuilder.newLocalProcessBuilder();
File out = new File(getWorkDirPath(), "testShellCommandProcess");
out.mkdirs();
out.delete();
try {
npb.setCommandLine("echo TEST > \"" + out.getAbsolutePath() + "\"");
NativeProcess process = npb.call();
int rc = process.waitFor();
if (!(process instanceof NbNativeProcess)) {
System.out.println("Test testShellCommandProcess is not applicable for " + process.getClass().getName() + " - skipped");
return;
}
assertEquals("echo with redirection status", 0, rc);
BufferedReader br = new BufferedReader(new FileReader(out));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
}
br.close();
assertEquals("TEST is expected to be written in " + out.getAbsolutePath(), "TEST", sb.toString().trim());
} finally {
out.delete();
}
}
示例10: createPath
import java.io.File; //导入方法依赖的package包/类
public static boolean createPath(String pathName){
File file = new File(pathName);
if(!file.exists()){
boolean suc = file.mkdirs();
return suc;
}else{
return true;
}
}
示例11: getDirectory
import java.io.File; //导入方法依赖的package包/类
public File getDirectory(String targetProject, String targetPackage) throws ShellException {
// targetProject is interpreted as a directory that must exist
//
// targetPackage is interpreted as a sub directory, but in package
// format (with dots instead of slashes). The sub directory will be
// created
// if it does not already exist
File project = new File(targetProject);
if (!project.isDirectory()) {
throw new ShellException(getString("Warning.9", targetProject));
}
StringBuilder sb = new StringBuilder();
StringTokenizer st = new StringTokenizer(targetPackage, ".");
while (st.hasMoreTokens()) {
sb.append(st.nextToken());
sb.append(File.separatorChar);
}
File directory = new File(project, sb.toString());
if (!directory.isDirectory()) {
boolean rc = directory.mkdirs();
if (!rc) {
throw new ShellException(getString("Warning.10", directory.getAbsolutePath()));
}
}
return directory;
}
示例12: saveDatabase
import java.io.File; //导入方法依赖的package包/类
@SuppressWarnings("ResultOfMethodCallIgnored")
private void saveDatabase(String jsonData) {
try {
File cachePath = new File(TallyStackerApplication.get().getCacheDir(), CHILD);
cachePath.mkdirs();
FileOutputStream stream = new FileOutputStream(cachePath + "/" + DATABASE_NAME);
BufferedOutputStream bos = new BufferedOutputStream(stream);
Exporter mExporter = new Exporter(bos);
mExporter.writeJson(jsonData);
mExporter.close();
stream.close();
File newFile = new File(cachePath, DATABASE_NAME);
Uri contentUri = FileProvider.getUriForFile(mContext, "com.calebtrevino.tallystacker.file_provider", newFile);
if (contentUri != null) {
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "TallyStacker Database");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Please have a look");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
shareIntent.setType(mContext.getContentResolver().getType(contentUri));
mContext.startActivity(Intent.createChooser(shareIntent, mContext.getResources().getText(R.string.send_to)));
}
} catch (IOException e) {
e.printStackTrace();
}
}
示例13: getExternalCacheDir
import java.io.File; //导入方法依赖的package包/类
private static String getExternalCacheDir(Context context) {
File dir = context.getExternalCacheDir();
if (dir == null) {
return null;
}
if (!dir.mkdirs() && !dir.exists()) {
return null;
}
return dir.getPath();
}
示例14: initProjectDirectoryFromWizard
import java.io.File; //导入方法依赖的package包/类
private File initProjectDirectoryFromWizard(Set<FileObject> projectRootDirectories) {
File projectDirectory = (File) wizardDescriptor.getProperty(WizardProperty.PROJECT_DIR.key());
if (projectDirectory != null) {
projectDirectory = FileUtil.normalizeFile(projectDirectory);
}
projectDirectory.mkdirs();
FileObject dir = FileUtil.toFileObject(projectDirectory);
projectRootDirectories.add(dir);
return projectDirectory;
}
示例15: createDiskCache
import java.io.File; //导入方法依赖的package包/类
private static synchronized DiskCache createDiskCache() {
final Context context = NimUIKit.getContext();
File cacheDir = StorageUtils.getOwnCacheDirectory(context, context.getPackageName() + "/cache/image/");
if (!cacheDir.exists()) {
cacheDir.mkdirs();
}
return DiskLruCacheWrapper.get(cacheDir, MAX_DISK_CACHE_SIZE);
}