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