1. 程式人生 > >java 寫出到檔案

java 寫出到檔案

//【1】建立輸出流檔案物件
        FileOutputStream fos = new FileOutputStream("/Users/student/Desktop/DTW_Java.txt",true);

        //【2】寫出檔案
        for(int i=0;i<resultDemo.size();i++){
            if(i%22==0){
                String str="\r\n";
                byte [] by = str.getBytes();   //把String型別轉為byte陣列
                fos.write(by
, 0, by.length); } for(int ii=0;ii < 3;ii++){ String str0 = String.valueOf(resultDemo.get(i).get(ii).doubleValue()); String str=str0+"\t"; byte [] by = str.getBytes(); //把String型別轉為byte陣列 fos.write(by, 0, by.length); } } //【3】關流
fos.close(); System.out.println("寫入完畢");