public class Files extends Object
Constructor and Description |
---|
Files() |
Modifier and Type | Method and Description |
---|---|
static void |
addDirectoryContentsToZip(File zipFile,
File directory)
Convenience method for
addFilesToZip(File zipFile, Map<String,File> files) . |
static void |
addDirectoryToZip(File zipFile,
File directory)
Convenience method for
addFilesToZip(File zipFile, Map<String,File> files) . |
static void |
addFilesToZip(File zipFile,
File[] files,
File baseDirectory)
Convenience method for
addFilesToZip(File zipFile, Map<String,File>
files). |
static void |
addFilesToZip(File zipFile,
Map<String,File> files)
This is where the action happens.
|
static void |
copy(File from,
File to)
Copy a file from one location to another
|
static String |
encodeURI(String path)
Encodes a file path for use as a URI.
|
static Map<String,File> |
listFilesRecursively(File directory,
boolean includeDirectories)
Lists all files recursively, starting at `directory`.
|
static Map<String,File> |
listFilesRecursively(File directory,
URI base,
boolean includeDirectories)
Lists all files recursively, starting at `directory`, resolving their
relative paths against `base`.
|
static List<String> |
listZipFiles(File zipfile)
Does not actually load the files, since that could potentially eat up your RAM.
|
static String |
read(File file)
Read text from file
|
static void |
unzip(File zip,
File dir)
Unzip the ZIP-file `zip` to the directory `dir`.
|
static void |
zip(File dir,
File zip)
Zip up the directory `dir` into a new ZIP-file `zip`.
|
public static void addDirectoryToZip(File zipFile, File directory) throws IOException
addFilesToZip(File zipFile, Map<String,File> files)
.
Appends all the files in the `directory` into the `zipFile` with paths
relative to `directory`s parent directory.zipFile
- The ZIP-file.directory
- The directory to add to the ZIP.IOException
- thrown when an IOException occurspublic static void addDirectoryContentsToZip(File zipFile, File directory) throws IOException
addFilesToZip(File zipFile, Map<String,File> files)
.
Appends all the files in the `directory` into the `zipFile` with paths
relative to the `directory`.zipFile
- The ZIP-file.directory
- The directory to add to the ZIP.IOException
- thrown when an IOException occurspublic static Map<String,File> listFilesRecursively(File directory, boolean includeDirectories) throws IOException
listFilesRecursively(File directory, URI base, boolean includeDirectories)
except
with directory and base pointing to the same directory.directory
- The directoryincludeDirectories
- whether or not to include the directories themselves in the resultIOException
- thrown when an IOException occurspublic static Map<String,File> listFilesRecursively(File directory, URI base, boolean includeDirectories) throws IOException
addFilesToZip(File zipFile, Map<String,File> files);
directory
- The directorybase
- The base URIincludeDirectories
- whether or not to include the directories themselves in the resultIOException
- thrown when an IOException occurspublic static List<String> listZipFiles(File zipfile)
zipfile
- The ZIP filepublic static void addFilesToZip(File zipFile, File[] files, File baseDirectory) throws IOException
addFilesToZip(File zipFile, Map<String,File>
files).
Appends all the `files` into the `zipFile` with paths relative to
`baseDirectory`.zipFile
- The ZIP-file.files
- The list of files to append to the ZIP-file.baseDirectory
- The directory to resolve the relative file paths against.IOException
- thrown when an IOException occurspublic static void addFilesToZip(File zipFile, Map<String,File> files) throws IOException
zipFile
- The ZIP file.files
- A map of all the files to add to the ZIP file, where the key is the ZIP entry name to use (the relative file paths).IOException
- thrown when an IOException occurspublic static void unzip(File zip, File dir) throws IOException
zip
- ZIP filedir
- output directoryIOException
- thrown when an IOException occurspublic static void zip(File dir, File zip) throws IOException
dir
- The directoryzip
- The ZIP fileIOException
- thrown when an IOException occurspublic static void copy(File from, File to) throws IOException
from
- Original locationto
- Target locationIOException
- thrown when an IOException occurspublic static String encodeURI(String path)
encodeURI("dir1/dir 2/file [ ]].xml") returns "dir1/dir%202/file%20%5B%20%20%5D%5D.xml"
path
- The pathCopyright © 2012–2022 The DAISY Consortium. All rights reserved.