Windows默认文件格式为UTF8格式,之前我们做过一个文件读写,但写入文件的方式是二进制格式,接下来,我们以windows默认的utf-8格式读写文件。
IOStream类
package com.anson.java;
import java.io.*;
/**
* 以windows默认UTF-8文件格式读写文件
* @author anson
*
*/
public class IOStream {
private String path;
public IOStream()
{
}
public IOStream(String path)
{
this.path=path;
}
/**
*
* utf-8windows默认文件编码格式写入文件
*/
public void WriteInfo()
{
try
{
File file=new File(path);
FileOutputStream fileOutputStream=new FileOutputStream(file);
OutputStreamWriter outputWriter=new OutputStreamWriter(fileOutputStream,"UTF-8");
String[] str=new String[]{"string 1","string 2","string 3","string 4"};
for(int i=0;i<str.length;i++)
{
outputWriter.append(&