Android reads and writes TXT files

Source: Internet
Author: User

The read and write operations of TXT text files are often used on the Android platform. The filewriter class of Java virtual machine can be used to process text mime files such as text files on the Android platform. This class is located in Java. Io. filewriter and provides multiple rewriting methods.

Filewriter (File file) // creates a file through a file object

Filewriter (File file, Boolean append) // if the file exists, the second parameter is set to false to overwrite. If it is set to true, it indicates the append method.

Filewriter (filedescriptor FD) // generate a file using the filedescriptor object
 
Filewriter (string filename) // write the file. The parameter is the complete path and file name.
 
Filewriter (string filename, Boolean append) // The second parameter is the same as the second overload method.

This class is inherited from Java. Io. outputstreamwriter and has
Void close ()
 
Void flush ()
 
String getencoding ()

Void write (char [] Buf, int offset, int count)
 
Void write (string STR, int offset, int count)
 
Void write (INT onechar)
 
 
You can also use Java. Io. Writer
Writer append (charsequence CSQ)
 
Writer append (charsequence CSQ, int start, int end)
 
Writer append (char C)
 
Abstract void close ()
 
Abstract void flush ()
 
Abstract void write (char [] Buf, int offset, int count)
 
Void write (string STR, int offset, int count)
 
Void write (INT onechar)
 
Void write (char [] BUF)
 
Void write (string Str)

For reading text files on the Android platform, you can use the filereader class, which is located in Java. io. filereader provides three rewrite Methods: filereader (File file), filereader (filedescriptor FD), and filereader (string filename). The only thing you need to note is that the filenotfoundexception exception is thrown. You can use the following methods for reading the parent class:

All methods of Java. Io. inputstreamreader are supported.
Void close ()
String getencoding ()
Int read (char [] Buf, int offset, int length)
Int read ()
Boolean ready ()

Supports all java. Io. Reader methods.
Abstract void close ()

Void mark (INT readlimit) // sets a flag
Boolean marksupported () // determines whether the mark () or reset () method is supported
Abstract int read (char [] Buf, int offset, int count)
Int read (charbuffer target)
Int read (char [] BUF)
Int read ()
Boolean ready ()
Void reset () // reset the read location
Long SKIP (Long Count)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.