public final class FileUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
copy(File source,
File dest)
Copies content of directory/file.
|
static byte[] |
getContentAsBytes(File f)
Read the contents of the file as a byte[]
|
static String |
getContentAsString(File f,
Charset charset)
Returns the content of the file as a String
|
static List<String> |
getContentAsStringList(File f,
Charset charset)
Each line in the file is returned as a element in the list.
|
static String |
getMimeType(File f)
Returns the mime-type of the file.
|
static void |
writeBytes(File f,
byte[] bytes)
Writes a byte[] to a file.
|
static void |
writeString(File f,
String content,
Charset charset)
Writes the provided String to the file using the provided charset encoding.
|
public static String getContentAsString(File f, Charset charset) throws IOException
f - File to read the content fromcharset - The charset to use to read the content.IOExceptionpublic static List<String> getContentAsStringList(File f, Charset charset) throws IOException
f - The file that needs to be read.charset - The charset to be used to read the file.IOExceptionpublic static byte[] getContentAsBytes(File f) throws IOException
f - The file to read the content from.IOExceptionpublic static String getMimeType(File f)
f - File for which mime-type needs to be determined.public static void writeString(File f, String content, Charset charset) throws IOException
f - The file the write the String to.content - The content String to write.charset - The charset encoding to use when writing.IOExceptionpublic static void writeBytes(File f, byte[] bytes) throws IOException
f - The file to write the byte[].bytes - The content to write.IOExceptionpublic static void copy(File source, File dest) throws IOException
source - The source directory/file.dest - The destination directory/file.IOException - When IO error happens.Copyright © 2014. All rights reserved.