/*
Writing only one row of data at a time requires invoking a specific
Method can be used.
*/
Package Com.second.File;
Import java.io.*;
/**
* Created by Hasee on 2016/11/15.
*/
public class WriteFile {
Private BufferedWriterBW =Null
public intOpenWrite (String Address, String Strcodeformat) {
if (Strcodeformat = =null | | Address = =null | | Address.length () = =0 | | Strcodeformat.length () = =0) {
Error code 101 The information entered is empty
Return101;
}
try {
BW =New BufferedWriter (
New OutputStreamWriter (
New FileOutputStream (address), Strcodeformat));
Return1;
}catch (FileNotFoundException e) {
E.printstacktrace ();
Return204;
}catch (Unsupportedencodingexception e) {
E.printstacktrace ();
Return201;
}
}
public intSave (String strLine) {
if (BW = =NULL) {
Return301;
}
try {
Bw.write (StrLine);
Return1;
}catch (IOException e) {
E.printstacktrace ();
}
Return0;
}
public int closewrite () {
if (BW = null) {
return 301 "
try {
bw.close () ;
return 1;
} catch (IOException e) {
E.printstacktrace () ;
return 301;
}
}
}
/span>
Java writes data into a file