Package com.hybris.datahub.core.io
Class TextFile
- java.lang.Object
-
- com.hybris.datahub.core.io.TextFile
-
public class TextFile extends java.lang.ObjectA convenience class for reading text from a file.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TextFileappend(java.lang.String txt)Adds text to the current content of this file.TextFileappendLine(java.lang.String txt)Appends text to the current content of this file and adds a new line separator at the end.voiddelete()Deletes file and its content from the file system.booleanequals(java.lang.Object obj)java.io.FilegetFilePath()Retrieves location of this text file.java.lang.StringgetPath()Retrieves location of this text file.inthashCode()java.lang.Stringread()Reads content of this file.java.lang.StringreadLine(long lnum)Reads specified line from this file.voidsave(java.lang.String txt)Saves text as the content of this text filejava.lang.StringtoString()
-
-
-
Constructor Detail
-
TextFile
public TextFile(java.lang.String path)
Instantiates a text file.- Parameters:
path- a path to the text file on the file system.
-
TextFile
public TextFile(java.lang.String dir, java.lang.String name)Instantiates a text file.- Parameters:
dir- path to the directory, in which the file should be created.name- name of the file to create.
-
TextFile
public TextFile(java.io.File file)
Instantiates a text file.- Parameters:
file- a file, in which the text is stored.
-
-
Method Detail
-
getPath
public java.lang.String getPath()
Retrieves location of this text file.- Returns:
- path to this text file on the file system.
-
getFilePath
public java.io.File getFilePath()
Retrieves location of this text file.- Returns:
- path to this text file on the file system.
-
save
public void save(java.lang.String txt) throws java.io.IOExceptionSaves text as the content of this text file- Parameters:
txt- a text to save in this file.- Throws:
java.io.IOException- when the text cannot be saved in this file.
-
append
public TextFile append(java.lang.String txt) throws java.io.IOException
Adds text to the current content of this file.- Parameters:
txt- a text to add.- Returns:
- this text file.
- Throws:
java.io.IOException- when saving the added text fails.
-
appendLine
public TextFile appendLine(java.lang.String txt) throws java.io.IOException
Appends text to the current content of this file and adds a new line separator at the end.- Parameters:
txt- a line of text to add to this file content- Returns:
- this text file
- Throws:
java.io.IOException- when saving the added line fails.
-
read
public java.lang.String read() throws java.io.IOExceptionReads content of this file.- Returns:
- text saved in this file.
- Throws:
java.io.IOException- if read failed.
-
readLine
public java.lang.String readLine(long lnum) throws java.io.IOExceptionReads specified line from this file.- Parameters:
lnum- number of the line to read. The line number starts from 1; there is no line 0 in a text file.- Returns:
- text on the specified line or
null, if the line number does not exist in this file. - Throws:
java.io.IOException- when reading the specified line fails
-
delete
public void delete() throws java.io.IOExceptionDeletes file and its content from the file system.- Throws:
java.io.IOException- if this file cannot be deleted.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-