Package io.bhagat.util
Class FileHandler
- java.lang.Object
-
- io.bhagat.util.FileHandler
-
public final class FileHandler extends java.lang.ObjectUtilities for reading and writing to files- Author:
- Bhagat
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Stringpaththe file path
-
Constructor Summary
Constructors Constructor Description FileHandler(java.lang.String path)Creates a FileHandler object for one file
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappend(java.lang.String text)Write to the file specified in the constructorstatic voidappend(java.lang.String path, java.lang.String text)Appends thetextto the end of the file specified by thepathjava.lang.StringgetPath()java.lang.Stringread()Read the file specified in the constructorstatic java.lang.Stringread(java.io.Reader reader)Reads from file specified by thereaderstatic java.lang.Stringread(java.lang.String path)Reads from file specified by thepathvoidsetPath(java.lang.String path)static voidwrite(java.io.Writer writer, java.lang.String text)Writes thetextto the file specified by thewritervoidwrite(java.lang.String text)Write to the file specified in the constructorstatic voidwrite(java.lang.String path, java.lang.String text)Writes thetextto the file specified by thepath
-
-
-
Method Detail
-
read
public java.lang.String read()
Read the file specified in the constructor- Returns:
- the read text
-
write
public void write(java.lang.String text)
Write to the file specified in the constructor- Parameters:
text- the text to be written into the file
-
append
public void append(java.lang.String text)
Write to the file specified in the constructor- Parameters:
text- the text to be appended into the file
-
getPath
public java.lang.String getPath()
- Returns:
- the path
-
setPath
public void setPath(java.lang.String path)
- Parameters:
path- the path to set
-
read
public static java.lang.String read(java.lang.String path)
Reads from file specified by thepath- Parameters:
path- the file path- Returns:
- the contents of the file
-
read
public static java.lang.String read(java.io.Reader reader)
Reads from file specified by thereader- Parameters:
reader- the reader- Returns:
- the contents of the file
-
write
public static void write(java.lang.String path, java.lang.String text)Writes thetextto the file specified by thepath- Parameters:
path- the file pathtext- the text to be written to the file
-
write
public static void write(java.io.Writer writer, java.lang.String text)Writes thetextto the file specified by thewriter- Parameters:
writer- a writertext- the text to be written to the file
-
append
public static void append(java.lang.String path, java.lang.String text)Appends thetextto the end of the file specified by thepath- Parameters:
path- the file pathtext- the text to be appended to the file
-
-