How-to articles, tricks, and solutions about TEXT-FILES

Clearing content of text file using php

To clear the contents of a text file using PHP, you can use the file_put_contents() function.

How can I read a large text file line by line using Java?

To read a large text file line by line in Java, you can use a BufferedReader and pass it a FileReader object to read the file. Here's an example of how you can do this:

How do I save a String to a text file using Java?

To save a String to a text file in Java, you can use the write method of the FileWriter class. Here's an example of how you can do this:

How to append text to an existing file in Java?

To append text to the end of an existing file in Java, you can use the Files.write() method from the java.nio.file package. This method allows you to write a sequence of characters to a file in a single operation.

How to get line count of a large file cheaply in Python?

You can use the line_count() function from the itertools module to get the line count of a large file cheaply in Python.

Java: How to read a text file

To read a text file in Java, you can use the BufferedReader class from the java.io package.

Reading a plain text file in Java

This code opens the file "filename.txt" and reads it line by line. Each line is printed to the console until the end of the file is reached.