幫你寫了。 希望對你有幫助。 /* * Txt.java * * Created on 2005年9月21日, 上午 3:21 * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */package untils;/** * * @author tao */ public class Txt { java.io.OutputStream fout=null; String[] text = {"aa","我","test"};
/** Creates a new instance of Txt */ public Txt() { } public void maketxt(){ try{ java.io.File f=new java.io.File("test.txt"); f.createNewFile(); fout=new java.io.FileOutputStream(f); for(int i=0;i<text.length;i++){ fout.write((text[i]+"\r\n").getBytes("utf-8")); } fout.flush(); fout.close(); }catch(Exception ex){} } public static void main(String[] args){ Txt aa = new Txt(); aa.maketxt(); }
for(int i=0;i<text.length;i++){
out.print(text[i] +",");
}
这里out 是PrintWriter对象。同目标输出流(FileWriter)合并一起使用,达到了象目标文件输出的目的。
希望對你有幫助。
/*
* Txt.java
*
* Created on 2005年9月21日, 上午 3:21
*
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
*/package untils;/**
*
* @author tao
*/
public class Txt {
java.io.OutputStream fout=null;
String[] text = {"aa","我","test"};
/** Creates a new instance of Txt */
public Txt() {
}
public void maketxt(){
try{
java.io.File f=new java.io.File("test.txt");
f.createNewFile();
fout=new java.io.FileOutputStream(f);
for(int i=0;i<text.length;i++){
fout.write((text[i]+"\r\n").getBytes("utf-8"));
}
fout.flush();
fout.close();
}catch(Exception ex){}
}
public static void main(String[] args){
Txt aa = new Txt();
aa.maketxt();
}
}