posts - 495,  comments - 11,  trackbacks - 0

          1


          //用FileOutputStream將內容寫入文本文件

          import java.io.*;
          public class FileOutputDemo
          {
          public static void main(String[] args)
          {
          ?? FileOutputStream out;
          ?? PrintStream p;
          ?? try
          ?? {
          ??? out = new FileOutputStream("myfile.txt");
          ??? p = new PrintStream(out);
          ??? p.println("Hello,World!");
          ??? p.close();
          ?? }
          ?? catch(Exception e)
          ?? {
          ??? System.err.println("Error writing to file!");
          ?? }
          }

          }

          2

          import java.io.*;

          class FSODemo
          {
          ?? public static void main(String args[]) throws Exception
          ?? {
          ???? String source="Beijing is the capital of China\n"
          ???? +"and it is a very beautiful city.\n"
          ???? +"Welcome to Beijing!";
          ???? byte buf[] = source.getBytes();
          ???? FileOutputStream f=new FileOutputStream("file.txt");
          ???? f.write(buf);
          ???? f.close();
          ???? System.out.println("文本已經成功寫入文件!");
          ?? }
          }

          posted on 2007-05-28 00:27 jadmin 閱讀(358) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 巴林左旗| 胶南市| 广安市| 宁明县| 荣成市| 响水县| 修水县| 开封县| 遂宁市| 尼玛县| 怀来县| 鄂尔多斯市| 会东县| 岚皋县| 江北区| 富民县| 县级市| 石阡县| 威海市| 康保县| 山阳县| 赤壁市| 鄱阳县| 扎兰屯市| 区。| 卫辉市| 九龙城区| 临武县| 隆尧县| 原阳县| 和田县| 邹平县| 乐至县| 涿鹿县| 福安市| 东安县| 临颍县| 广水市| 新邵县| 商丘市| 竹山县|