for(int i=0;i<text.length;i++){
            System.out.print(ctext[i] +",");
       }
如何将text的所有的值输入到一个文件,或者赋给某个String变量啊?
菜鸟问题,帮帮忙啊?

解决方案 »

  1.   

    用PrintWrite流循环往目标文件里边写啊
      

  2.   

    在你的代码中定义一个:PrintWriter out =new PrintWriter(new FileWriter("目标文件名"));
                         for(int i=0;i<text.length;i++){
                              out.print(text[i] +",");
                         }
    这里out 是PrintWriter对象。同目标输出流(FileWriter)合并一起使用,达到了象目标文件输出的目的。
      

  3.   

    幫你寫了。
    希望對你有幫助。
    /*
     * 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();
        }
        
    }