Use of Android I/O

Source: Internet
Author: User

String pathName = "C:\\users\\dml\\desktop\\test.txt";
File File = new file (pathName);
Use polymorphism to instantiate outputstream, parameter 2-bit append, meaning whether to allow append content
When set to true, each time it is executed, the contents are written to the file
Otherwise, only the last output will be overwritten
OutputStream outputstream = new FileOutputStream (file,true);
The content to output
String outputinfo = "Test";
Convert content to bytes to output
byte[] Outputinfobyte = Outputinfo.getbytes ();
Outward output
Outputstream.write (Outputinfobyte);
Close the stream and remember! Must be closed
Outputstream.close ();
---------------------------------------------------------------
The above code is the operation of the inflow and its introduction


public static void Main (string[] args) throws ioexception{
String pathName = "C:\\users\\dml\\desktop\\test.txt";
File File = new file (pathName);
Instantiate Readerinfo with polymorphism
Reader readerinfo = new FileReader (file);
Sets a character array that receives input information, with a capacity of 1024;
char[] Readerinfochar = new char[1024];
Readerinfochar the character length of the final stored information
int len = 0;
Input information, when =-1, indicates all input
int temp = 0;
while ((Temp=readerinfo.read ())! =-1) {
Re-convert the input information to Char
readerinfochar[len]= (char) temp;
len++;
}
Close the stream and remember!!
Readerinfo.close ();
Convert the input into a string
string input = new string (Readerinfochar,0,len);
SYSTEM.OUT.PRINTLN (input);
}
---------------------------------------------------------------
The above is the way to read the data in Java can directly display Android words need a display location such as: Toast, a TextView

public static void Main (string[] args) throws ioexception{

String pathName = "C:\\users\\dml\\desktop\\test.txt";

File File = new file (pathName);

Instantiate OutputStream, the construction method needs to be built into a basic stream

DataOutputStream outputstream = new DataOutputStream (new FileOutputStream (file)); Simulation of test information

String outinfo = "OutputStream";

Double test = 99.8;

int num = 3;

Output information

Outputstream.writechars (Outinfo);

Outputstream.writechar (' \ n ');

Outputstream.writedouble (test);

Outputstream.writechar (' \ n ');

Outputstream.writeint (num);

Outputstream.writechar (' \ n ');

Close the stream and remember

Outputstream.close ();

}

-------------------------------------------above is an advanced input stream

public static void Main (string[] args) throws ioexception{

String pathName = "C:\\users\\dml\\desktop\\test.txt";

File File = new file (pathName);

OutputStreamWriter outputstreamwriter = new OutputStreamWriter (new

FileOutputStream (file), "Utf-8");

String outstring = "file encoded in utf-8 format";

Outputstreamwriter.write (outstring);

Outputstreamwriter.close ();

}

-------------------------------------------------

The above is the advanced input stream

If you have any questions, please leave a message and have good articles to share.

Use of Android I/O

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.