JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java 新手區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
作者 陣列內容怎寫出檔???
game1meat





發文: 87
積分: 0
於 2009-05-17 21:42 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我有一個陣列 x={1,2,3,4,5,6,7,8,9,10}

怎樣把陣列裡的元素寫出到一個文字檔??


reply to postreply to post
作者 Re:陣列內容怎寫出檔??? [Re:game1meat]
keung2640





發文: 19
積分: 0
於 2009-05-18 09:55 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import java.io.*;
public class Out{
  public static void main(String[] args){
    String buffer = "";
    try{
      FileOutputStream out = new FileOutputStream("output.txt");
      int[] x = {1,2,3,4,5,6,7,8,9,10};
      
      for(int anInt : x)
        buffer += anInt+" ";
        
      for(int i=0; i<buffer.length(); i++)
        out.write((byte)buffer.charAt(i));
        
      out.close();
    }catch(IOException e){
      System.out.println(e.getMessage());
    }
  }
}


reply to postreply to post
作者 Re:陣列內容怎寫出檔??? [Re:game1meat]
conceal





發文: 7
積分: 0
於 2009-05-18 09:59 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
1
2
3
4
5
6
7
8
9
int[] x={1,2,3,4,5,6,7,8,9,10};
FileWriter fw=new FileWriter("test.txt");
BufferedWriter bfw=new BufferedWriter(fw);
for(int i=0; i<x.length; i++)
{
    bfw.write(Integer.toString(x[i])+" ");
}
bfw.flush();
fw.close();


conceal edited on 2009-05-18 10:30
reply to postreply to post
» JWorld@TW »  Java 新手區

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8