/** Returns a writer for writing to this file. Parent directories will be created if necessary. * @param append If false, this file will be overwritten if it exists, otherwise it will be appended. * @param charset May be null to use the default charset. * @throws GdxRuntimeException if this file handle represents a directory, if it is a {@link FileType#Classpath} or * {@link FileType#Internal} file, or if it could not be written. */ public Writer writer (boolean append, String charset) { if (type == FileType.Classpath) throw new GdxRuntimeException("Cannot write to a classpath file: " + file); if (type == FileType.Internal) throw new GdxRuntimeException("Cannot write to an internal file: " + file); parent().mkdirs(); try { FileOutputStream output = new FileOutputStream(file(), append); if (charset == null) return new OutputStreamWriter(output); else return new OutputStreamWriter(output, charset); } catch (IOException ex) { if (file().isDirectory()) throw new GdxRuntimeException("Cannot open a stream to a directory: " + file + " (" + type + ")", ex); throw new GdxRuntimeException("Error writing file: " + file + " (" + type + ")", ex); } }
/** Returns a writer for writing to this file. Parent directories will be created if necessary. * @param append If false, this file will be overwritten if it exists, otherwise it will be appended. * @param charset May be null to use the default charset. * @throws GdxRuntimeException if this file handle represents a directory, if it is a {@link FileType#Classpath} or * {@link FileType#Internal} file, or if it could not be written. */ public Writer writer (boolean append, String charset) { if (type == FileType.Classpath) throw new GdxRuntimeException("Cannot write to a classpath file: " + file); if (type == FileType.Internal) throw new GdxRuntimeException("Cannot write to an internal file: " + file); parent().mkdirs(); try { FileOutputStream output = new FileOutputStream(file(), append); if (charset == null) return new OutputStreamWriter(output); else return new OutputStreamWriter(output, charset); } catch (IOException ex) { if (file().isDirectory()) throw new GdxRuntimeException("Cannot open a stream to a directory: " + file + " (" + type + ")", ex); throw new GdxRuntimeException("Error writing file: " + file + " (" + type + ")", ex); } }
/** Returns a stream for writing to this file. Parent directories will be created if necessary. * @param append If false, this file will be overwritten if it exists, otherwise it will be appended. * @throws GdxRuntimeException if this file handle represents a directory, if it is a {@link FileType#Classpath} or * {@link FileType#Internal} file, or if it could not be written. */ public OutputStream write (boolean append) { if (type == FileType.Classpath) throw new GdxRuntimeException("Cannot write to a classpath file: " + file); if (type == FileType.Internal) throw new GdxRuntimeException("Cannot write to an internal file: " + file); parent().mkdirs(); try { return new FileOutputStream(file(), append); } catch (Exception ex) { if (file().isDirectory()) throw new GdxRuntimeException("Cannot open a stream to a directory: " + file + " (" + type + ")", ex); throw new GdxRuntimeException("Error writing file: " + file + " (" + type + ")", ex); } }
/** Returns a stream for writing to this file. Parent directories will be created if necessary. * @param append If false, this file will be overwritten if it exists, otherwise it will be appended. * @throws GdxRuntimeException if this file handle represents a directory, if it is a {@link FileType#Classpath} or * {@link FileType#Internal} file, or if it could not be written. */ public OutputStream write (boolean append) { if (type == FileType.Classpath) throw new GdxRuntimeException("Cannot write to a classpath file: " + file); if (type == FileType.Internal) throw new GdxRuntimeException("Cannot write to an internal file: " + file); parent().mkdirs(); try { return new FileOutputStream(file(), append); } catch (Exception ex) { if (file().isDirectory()) throw new GdxRuntimeException("Cannot open a stream to a directory: " + file + " (" + type + ")", ex); throw new GdxRuntimeException("Error writing file: " + file + " (" + type + ")", ex); } }
static private void copyDirectory (FileHandle sourceDir, FileHandle destDir) { destDir.mkdirs(); FileHandle[] files = sourceDir.list(); for (int i = 0, n = files.length; i < n; i++) { FileHandle srcFile = files[i]; FileHandle destFile = destDir.child(srcFile.name()); if (srcFile.isDirectory()) copyDirectory(srcFile, destFile); else copyFile(srcFile, destFile); } } }
if (!outputFile.exists()) break; new FileHandle(outputFile).parent().mkdirs(); page.imageName = outputFile.getName();
static private void copyDirectory (FileHandle sourceDir, FileHandle destDir) { destDir.mkdirs(); FileHandle[] files = sourceDir.list(); for (int i = 0, n = files.length; i < n; i++) { FileHandle srcFile = files[i]; FileHandle destFile = destDir.child(srcFile.name()); if (srcFile.isDirectory()) copyDirectory(srcFile, destFile); else copyFile(srcFile, destFile); } } }
if (!outputFile.exists()) break; new FileHandle(outputFile).parent().mkdirs(); page.imageName = outputFile.getName();
/** Copies this file or directory to the specified file or directory. If this handle is a file, then 1) if the destination is a * file, it is overwritten, or 2) if the destination is a directory, this file is copied into it, or 3) if the destination * doesn't exist, {@link #mkdirs()} is called on the destination's parent and this file is copied into it with a new name. If * this handle is a directory, then 1) if the destination is a file, GdxRuntimeException is thrown, or 2) if the destination is * a directory, this directory is copied into it recursively, overwriting existing files, or 3) if the destination doesn't * exist, {@link #mkdirs()} is called on the destination and this directory is copied into it recursively. * @throws GdxRuntimeException if the destination file handle is a {@link FileType#Classpath} or {@link FileType#Internal} * file, or copying failed. */ public void copyTo (FileHandle dest) { if (!isDirectory()) { if (dest.isDirectory()) dest = dest.child(name()); copyFile(this, dest); return; } if (dest.exists()) { if (!dest.isDirectory()) throw new GdxRuntimeException("Destination exists but is not a directory: " + dest); } else { dest.mkdirs(); if (!dest.isDirectory()) throw new GdxRuntimeException("Destination directory cannot be created: " + dest); } copyDirectory(this, dest.child(name())); }
/** Copies this file or directory to the specified file or directory. If this handle is a file, then 1) if the destination is a * file, it is overwritten, or 2) if the destination is a directory, this file is copied into it, or 3) if the destination * doesn't exist, {@link #mkdirs()} is called on the destination's parent and this file is copied into it with a new name. If * this handle is a directory, then 1) if the destination is a file, GdxRuntimeException is thrown, or 2) if the destination is * a directory, this directory is copied into it recursively, overwriting existing files, or 3) if the destination doesn't * exist, {@link #mkdirs()} is called on the destination and this directory is copied into it recursively. * @throws GdxRuntimeException if the destination file handle is a {@link FileType#Classpath} or {@link FileType#Internal} * file, or copying failed. */ public void copyTo (FileHandle dest) { if (!isDirectory()) { if (dest.isDirectory()) dest = dest.child(name()); copyFile(this, dest); return; } if (dest.exists()) { if (!dest.isDirectory()) throw new GdxRuntimeException("Destination exists but is not a directory: " + dest); } else { dest.mkdirs(); if (!dest.isDirectory()) throw new GdxRuntimeException("Destination directory cannot be created: " + dest); } copyDirectory(this, dest.child(name())); }
@Override public void createDirectory(String... path) throws PlayerDataException { if (path.length == 0) { throw new PlayerDataException("No path specified"); } FileHandle directory = resolve(path); if (directory.exists()) { return; } ensureDataDirectoryExists(); directory.mkdirs(); }
private void ensureDirectoryExistsForFile(String... filepath) { ensureDataDirectoryExists(); FileHandle file = resolve(filepath); if (file.exists()) { return; } FileHandle parent = file.parent(); if (parent.exists()) { return; } parent.mkdirs(); }
@Initiate(priority = AutumnActionPriority.TOP_PRIORITY) void init() { modulesDir.mkdirs(); if (repoCacheFile.exists()) { Array<RepositoryModuleData> newArray = json.fromJson(Array.class, RepositoryModuleData.class, repoCacheFile); repositoryModules.clear(); for (RepositoryModuleData moduleData : newArray) { repositoryModules.put(moduleData.name, moduleData); } Gdx.app.log(TAG, "Cached data was loaded"); } requestRefreshRepositoryIfNeeded(); }