import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
public class FileWriter {
private static FileOutputStream getOutputStream(String filePath) {
File file = new File(filePath);
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file, true);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return fos;
}
/**
* @param args
*/
public static void main(String[] args) {
OutputStream fos = null;
try {
fos = getOutputStream("e:/yangdongxin.txt");
String data = "";
for (int i = 0; i < 10; i++) {
data = i + "|"+"user"+i+"|0|/r/n";
fos.write(data.getBytes("utf-8"));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}