posts - 495,  comments - 11,  trackbacks - 0

          1


          //用FileOutputStream將內(nèi)容寫入文本文件

          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("文本已經(jīng)成功寫入文件!");
          ?? }
          }

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

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 田东县| 高邮市| 塘沽区| 黄石市| 麻江县| 呼玛县| 禹州市| 城市| 无棣县| 高台县| 乌拉特中旗| 滨州市| 荆门市| 酉阳| 鹤庆县| 河北区| 永年县| 环江| 定结县| 慈利县| 衡南县| 邵阳县| 冀州市| 维西| 固始县| 阿巴嘎旗| 昂仁县| 上栗县| 吐鲁番市| 崇仁县| 武强县| 漳浦县| 峨山| 新沂市| 渝北区| 客服| 北辰区| 西丰县| 新野县| 林州市| 仪陇县|