Package com.netlang.io
Class TextFile
java.lang.Object
com.netlang.io.TextFile
Class for reading and writing text files. After opening a file for read or write it must be closed.
Example - Write lines to a new file.
Example - Read 10 lines from a text file at the local file system.
Example - Write lines to a new file.
TextFile file1 = new TextFile(new File("C:\\Temp\\test.txt"),TextFile.CREATE,"unicode-1-1-utf-8");
file1.write("Hello World!");
file1.close();
Example - Read 10 lines from a text file at the local file system.
TextFile file1 = new TextFile(new File("C:\\Temp\\test.txt"),TextFile.OPEN,"UTF-8");
for(int i = 0; i < 10; i++) {
Log.info(file1.readLine(), null);
}
file1.close();
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTextFile(NetlangFile file, int openoption, String encoding) Create a new Text file for reading or writing.TextFile(com.netlang.session.NetlangSession session, NetlangFile file, int openoption, String encoding) Create a new Text file for reading or writing.TextFile(com.netlang.session.NetlangSession session, String id, String path, int openoption, String encoding) Create a new Text file for reading or writing.Create a new Text file for reading or writing.Create a new Text file for reading or writing.Create a new Text file for reading or writing. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close this file.static voidvoidopen()Open the file for read or write, this function will be called when a new instance of this class is created.readAll()Read all lines in this file.readLine()Read one line from the file.voidWrites the passed string to the filevoidWrites the passed string with EOL.
-
Field Details
-
CREATE
public static int CREATECreate mode -
OPEN
public static int OPENOpen only mode -
APPEND
public static int APPENDAppend mode -
TEMPORARY
public static int TEMPORARYTemporary file.
-
-
Constructor Details
-
TextFile
public TextFile(String id, String path, int openoption, String encoding) throws com.net4z.APIException Create a new Text file for reading or writing.- Parameters:
id-path-openoption-encoding-- Throws:
com.net4z.APIException
-
TextFile
Create a new Text file for reading or writing.- Parameters:
filepath-openoption-encoding-- Throws:
com.net4z.APIException
-
TextFile
Create a new Text file for reading or writing.- Parameters:
file-openoption-encoding-- Throws:
com.net4z.APIException
-
TextFile
Create a new Text file for reading or writing.- Parameters:
file-openoption-encoding-- Throws:
com.net4z.APIException
-
TextFile
public TextFile(com.netlang.session.NetlangSession session, NetlangFile file, int openoption, String encoding) throws com.net4z.APIException Create a new Text file for reading or writing.- Parameters:
session-file-openoption-encoding-- Throws:
com.net4z.APIException
-
TextFile
public TextFile(com.netlang.session.NetlangSession session, String id, String path, int openoption, String encoding) throws com.net4z.APIException Create a new Text file for reading or writing.- Parameters:
session- the Netlang sessionid- the resource idpath- the relative path to the fileopenoption- Append, Create or Openencoding- the text encoding, e.g. "UTF-8"- Throws:
com.net4z.APIException
-
-
Method Details
-
main
- Throws:
Exception
-
open
public void open() throws com.net4z.APIExceptionOpen the file for read or write, this function will be called when a new instance of this class is created.- Throws:
com.net4z.APIException
-
write
Writes the passed string to the file- Parameters:
v-- Throws:
Exceptioncom.net4z.APIException
-
writeLine
Writes the passed string with EOL.- Parameters:
v-- Throws:
Exceptioncom.net4z.APIException
-
readLine
Read one line from the file.- Returns:
- Throws:
com.net4z.APIException
-
readAll
Read all lines in this file.- Returns:
- Throws:
com.net4z.APIException
-
close
public void close() throws com.net4z.APIExceptionClose this file.- Throws:
com.net4z.APIException
-