public class FileWriter
extends java.lang.Object
Constructor and Description |
---|
FileWriter(java.io.File file) |
FileWriter(java.io.File file,
boolean append) |
FileWriter(java.lang.String filePath) |
FileWriter(java.lang.String filePath,
boolean append) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the writer.
|
void |
reopen()
Resets the current location in the file to the beginning
|
java.lang.String |
toString() |
void |
write(java.lang.String text)
Writes the given string into the file
|
static void |
writeFile(java.io.File targetFile,
java.lang.String content)
Writes to the given file with only the content given
|
static void |
writeFile(java.lang.String targetFilePath,
java.lang.String content)
Writes to the given file with only the content given
|
void |
writeLine(java.lang.String text)
Writes the given text as a line in the file
|
static void |
writeSerializedFile(java.io.File targetFile,
java.io.Serializable content)
Serializes and writes the provided object to a file
|
static void |
writeSerializedFile(java.lang.String targetFilePath,
java.io.Serializable content)
Serializes and writes the provided object to a file
|
public FileWriter(java.io.File file) throws java.io.IOException
file
- the file to write tojava.io.IOException
- if the file can't be openedpublic FileWriter(java.io.File file, boolean append) throws java.io.IOException
file
- the file to write toappend
- whether to append to the filejava.io.IOException
- if the file can't be openedpublic FileWriter(java.lang.String filePath) throws java.io.IOException
filePath
- the path of the file to write tojava.io.IOException
- if the file can't be openedpublic FileWriter(java.lang.String filePath, boolean append) throws java.io.IOException
filePath
- the path of the file to write toappend
- whether to append to the filejava.io.IOException
- if the file can't be openedpublic static void writeFile(java.io.File targetFile, java.lang.String content) throws java.io.IOException
targetFile
- the file to write tocontent
- the content to put in the filejava.io.IOException
- if the file can't be openedpublic static void writeFile(java.lang.String targetFilePath, java.lang.String content) throws java.io.IOException
targetFilePath
- the path of the file to write tocontent
- the content to put in the filejava.io.IOException
- if the file can't be openedpublic static void writeSerializedFile(java.io.File targetFile, java.io.Serializable content) throws java.io.IOException
targetFile
- the file to write tocontent
- the object to put in the filejava.io.IOException
- if the file can't be openedpublic static void writeSerializedFile(java.lang.String targetFilePath, java.io.Serializable content) throws java.io.IOException
targetFilePath
- the path of the file to write tocontent
- the object to put in the filejava.io.IOException
- if the file can't be openedpublic void close() throws java.io.IOException
java.io.IOException
- if the file was already closedpublic void reopen() throws java.io.IOException
java.io.IOException
- if the file can't be reopenedpublic java.lang.String toString()
toString
in class java.lang.Object
public void write(java.lang.String text) throws java.io.IOException
text
- the text to write to the filejava.io.IOException
- if the text can't be writtenpublic void writeLine(java.lang.String text) throws java.io.IOException
text
- the text to write to the filejava.io.IOException
- if the text can't be written