The source code of the Stenway ReliableTXT reference library can be found on GitHub
You can find JAR files or dependency information on the Maven Central Repository
Join lines
ReliableTxtDocument document = new ReliableTxtDocument("Line1", "Line2", "Line3");
Split into lines
ReliableTxtDocument document = new ReliableTxtDocument("Line1\nLine2\nLine3"); String[] lines = document.getLines();
Specify encoding
var docUtf8 = new ReliableTxtDocument("a"); var docUtf16 = new ReliableTxtDocument("a", ReliableTxtEncoding.UTF_16); var document = new ReliableTxtDocument("a"); document.setEncoding(ReliableTxtEncoding.UTF_16_REVERSE);
Encode as bytes
var document = new ReliableTxtDocument("a"); byte[] bytes = document.getBytes();
Save as ReliableTXT file
var document = new ReliableTxtDocument("Line1\nLine2"); document.save("UTF-8.txt");
Load a ReliableTXT file
ReliableTxtDocument document = ReliableTxtDocument.load("UTF-16.txt");
Load a ReliableTXT document from memory
byte[] bytes = new byte[] {(byte)0xFE, (byte)0xFF, 0x00, 0x61}; ReliableTxtDocument document = new ReliableTxtDocument(bytes);
Handle invalid documents
try { var document = ReliableTxtDocument.load("Readme.txt"); } catch (ReliableTxtException e) { ... }
Code points and supplementary characters
int[] codePoints = new int[] {0x61, 0xDF, 0x6771, 0x20007}; ReliableTxtDocument document = new ReliableTxtDocument(codePoints);
Read a ReliableTXT file line by line
try (ReliableTxtStreamReader reader = new ReliableTxtStreamReader("BigFile.txt")) { String line = null; while ((line = reader.readLine()) != null) { ... } }
Write a ReliableTXT file line by line
try (ReliableTxtStreamWriter writer = new ReliableTxtStreamWriter("MyBigFile.txt")) { for (int i=1; i<=100000000; i++) { writer.writeLine("Line "+i); } }
Specify encoding
ReliableTxtStreamWriter writer = new ReliableTxtStreamWriter("MyBigFile.txt", ReliableTxtEncoding.UTF_16);
Append
ReliableTxtStreamWriter writer = new ReliableTxtStreamWriter("MyBigFile.txt", true);