public abstract class Files extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Files.MoreFiles
The Class MoreFiles.
|
| Modifier and Type | Method and Description |
|---|---|
static com.google.common.io.ByteSink |
asByteSink(File file,
com.google.common.io.FileWriteMode... modes)
As byte sink.
|
static com.google.common.io.ByteSink |
asByteSink(Path path,
OpenOption... options)
As byte sink.
|
static com.google.common.io.ByteSource |
asByteSource(File file)
As byte source.
|
static com.google.common.io.ByteSource |
asByteSource(Path path,
OpenOption... options)
As byte source.
|
static com.google.common.io.CharSink |
asCharSink(File file,
Charset charset,
com.google.common.io.FileWriteMode... modes)
As char sink.
|
static com.google.common.io.CharSink |
asCharSink(Path path,
Charset charset,
OpenOption... options)
As char sink.
|
static com.google.common.io.CharSource |
asCharSource(File file,
Charset charset)
As char source.
|
static com.google.common.io.CharSource |
asCharSource(Path path,
Charset charset,
OpenOption... options)
As char source.
|
static void |
copy(File from,
File to) |
static void |
copy(File from,
OutputStream to) |
static void |
createParentDirectories(Path path,
FileAttribute<?>... attrs)
Creates the parent directories.
|
static void |
createParentDirs(File file)
Creates the parent dirs.
|
static File |
createTempDir()
Deprecated.
For Android users, see the Data and File
Storage overview to select an appropriate temporary directory (perhaps
context.getCacheDir()). For developers on Java 7 or later, use Files.createTempDirectory(java.nio.file.Path, java.lang.String, java.nio.file.attribute.FileAttribute<?>...), transforming it to a File using toFile() if needed. |
static void |
deleteDirectoryContents(Path path,
com.google.common.io.RecursiveDeleteOption... options)
Delete directory contents.
|
static void |
deleteRecursively(Path path,
com.google.common.io.RecursiveDeleteOption... options) |
static boolean |
equal(File file1,
File file2) |
static boolean |
equal(Path path1,
Path path2) |
static com.google.common.graph.Traverser<File> |
fileTraverser() |
static String |
getFileExtension(Path path)
Gets the file extension.
|
static String |
getFileExtension(String fullName)
Gets the file extension.
|
static String |
getNameWithoutExtension(Path path)
Gets the name without extension.
|
static String |
getNameWithoutExtension(String file)
Gets the name without extension.
|
static ImmutableList<Path> |
listFiles(Path dir) |
static MappedByteBuffer |
map(File file) |
static MappedByteBuffer |
map(File file,
FileChannel.MapMode mode) |
static MappedByteBuffer |
map(File file,
FileChannel.MapMode mode,
long size) |
static void |
move(File from,
File to) |
static BufferedReader |
newReader(File file,
Charset charset) |
static BufferedWriter |
newWriter(File file,
Charset charset) |
static com.google.common.graph.Traverser<Path> |
pathTraverser() |
static List<String> |
readLines(File file,
Charset charset) |
static String |
simplifyPath(String pathname) |
static byte[] |
toByteArray(File file)
To byte array.
|
static void |
touch(File file) |
static void |
touch(Path path) |
static void |
write(byte[] from,
File to) |
public static BufferedReader newReader(File file, Charset charset) throws FileNotFoundException
file - charset - FileNotFoundException - the file not found exceptionpublic static BufferedWriter newWriter(File file, Charset charset) throws FileNotFoundException
file - charset - FileNotFoundException - the file not found exceptionpublic static com.google.common.io.ByteSource asByteSource(File file)
file - @SafeVarargs public static com.google.common.io.ByteSource asByteSource(Path path, OpenOption... options)
path - options - @SafeVarargs public static com.google.common.io.ByteSink asByteSink(File file, com.google.common.io.FileWriteMode... modes)
file - modes - @SafeVarargs public static com.google.common.io.ByteSink asByteSink(Path path, OpenOption... options)
path - options - public static com.google.common.io.CharSource asCharSource(File file, Charset charset)
file - charset - @SafeVarargs public static com.google.common.io.CharSource asCharSource(Path path, Charset charset, OpenOption... options)
path - charset - options - @SafeVarargs public static com.google.common.io.CharSink asCharSink(File file, Charset charset, com.google.common.io.FileWriteMode... modes)
file - charset - modes - @SafeVarargs public static com.google.common.io.CharSink asCharSink(Path path, Charset charset, OpenOption... options)
path - charset - options - public static byte[] toByteArray(File file) throws IOException
file - IOException - Signals that an I/O exception has occurred.public static void write(byte[] from,
File to)
throws IOException
from - to - IOException - Signals that an I/O exception has occurred.public static boolean equal(File file1, File file2) throws IOException
file1 - file2 - IOException - Signals that an I/O exception has occurred.public static boolean equal(Path path1, Path path2) throws IOException
path1 - path2 - IOException - Signals that an I/O exception has occurred.public static void touch(File file) throws IOException
file - IOException - Signals that an I/O exception has occurred.public static void touch(Path path) throws IOException
path - IOException - Signals that an I/O exception has occurred.@Deprecated public static File createTempDir()
context.getCacheDir()). For developers on Java 7 or later, use Files.createTempDirectory(java.nio.file.Path, java.lang.String, java.nio.file.attribute.FileAttribute<?>...), transforming it to a File using toFile() if needed.public static void createParentDirs(File file) throws IOException
file - IOException - Signals that an I/O exception has occurred.@SafeVarargs public static void createParentDirectories(Path path, FileAttribute<?>... attrs) throws IOException
path - attrs - IOException - Signals that an I/O exception has occurred.public static void copy(File from, OutputStream to) throws IOException
from - to - IOException - Signals that an I/O exception has occurred.public static void copy(File from, File to) throws IOException
from - to - IOException - Signals that an I/O exception has occurred.public static void move(File from, File to) throws IOException
from - to - IOException - Signals that an I/O exception has occurred.public static List<String> readLines(File file, Charset charset) throws IOException
file - charset - IOException - Signals that an I/O exception has occurred.public static MappedByteBuffer map(File file) throws IOException
file - IOException - Signals that an I/O exception has occurred.public static MappedByteBuffer map(File file, FileChannel.MapMode mode) throws IOException
file - mode - IOException - Signals that an I/O exception has occurred.public static MappedByteBuffer map(File file, FileChannel.MapMode mode, long size) throws IOException
file - mode - size - IOException - Signals that an I/O exception has occurred.public static String getNameWithoutExtension(String file)
file - public static String getNameWithoutExtension(Path path)
path - public static String getFileExtension(String fullName)
fullName - public static String getFileExtension(Path path)
path - public static com.google.common.graph.Traverser<File> fileTraverser()
public static com.google.common.graph.Traverser<Path> pathTraverser()
public static ImmutableList<Path> listFiles(Path dir) throws IOException
dir - IOException - Signals that an I/O exception has occurred.@SafeVarargs public static void deleteRecursively(Path path, com.google.common.io.RecursiveDeleteOption... options) throws IOException
path - options - IOException - Signals that an I/O exception has occurred.@SafeVarargs public static void deleteDirectoryContents(Path path, com.google.common.io.RecursiveDeleteOption... options) throws IOException
path - options - IOException - Signals that an I/O exception has occurred.Copyright © 2021. All rights reserved.