<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    javainthinking

    XL的個性空間和java學習之旅

      BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      13 隨筆 :: 13 文章 :: 20 評論 :: 1 Trackbacks

    package com.xionglian.common;

    import java.io.File;
    import java.net.URL;
    import java.io.InputStream;
    import java.io.IOException;
    import java.io.BufferedWriter;
    import java.io.FileWriter;

    /**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2000</p>
     * <p>Company: </p>
     * @author 熊煉
     * @version 1.0
     */

    public class FileHandle
    {

      public FileHandle()
      {
      }

      /**
       * filename path和URL之間的轉換
       */
      public void _File_URL()
      {
        String path = File.separator + "a";
        System.out.println(path);
        //coverting Between a filename and a URL
        //create a file object
        File file = new File("filename");

        //covert a file object to a URL
        URL url = null;
        try
        {
          url=file.toURL();
          System.out.println(url);
        }
        catch(Exception  e)
        {
          e.printStackTrace();
        }

        //convert a URL to a file object
        file=new File(url.getFile());

        //read the file using the URL
        try
        {
          InputStream is=url.openStream();
          //read from the InputStream
        }
        catch(IOException e)
        {
          e.printStackTrace();
        }
      }

      /**
       * 從relative path到absolute path之間的轉換
       */
      public void rel_to_abspath()
      {
        File file=new File("filename.txt");//filename.txt doesn't need exist
        file=file.getAbsoluteFile();//C:\Documents and Settings\xl\桌面\First\filename

        file=new File("test"+File.separator+"filename.txt");
        file=file.getAbsoluteFile();//C:\Documents and Settings\xl\桌面\First\test\filename.txt
      }

      /**
       * 判斷兩個filename path是否指向同一file
       * @return boolean
       */
      public boolean isSameFile()
      {
        File file1=new File("filename");
        File file2=new File("/filename");
        //file1.equals(file2)=false;
        try
        {
          //利用File.getCanonicalFile()消除多余的symbol links或者"."和".."
          file1.getCanonicalFile();
          file2.getCanonicalFile();
        }
        catch(Exception e){}
        return file1.equals(file2);//true
      }

      /**
       * 創(chuàng)建一個臨時temporary文件
       * @param args
       */
      public void createTempFile()
      {
        try
          {
            //create temporary file
            File temp = new File("temp", ".txt");
            //推出程序時刪除temp文件
            temp.deleteOnExit();

            //向temp文件中寫content
            BufferedWriter out = new BufferedWriter(new FileWriter(temp));
            out.write("熊煉");
            out.close();
          }
          catch(IOException e)
          {
            e.printStackTrace();
          }
      }

      /**
       * File、directory更名或File移動到另一個位置
       * @param args
       */
      public void rename_move_File()
      {
        //rename a File or directory
        File file1=new File("oldname");
        File file2=new File("newname");
        file1.renameTo(file2);

        //move File
        File file=new File("filename");
        File dir=new File("directoryname");
        file.renameTo(new File(dir,file.getName()));
      }

      public static void main(String[] args)
      {

      }

     

      }

    posted on 2005-07-27 09:07 XL的個性空間和java學習之旅 閱讀(2116) 評論(0)  編輯  收藏 所屬分類: 實用操作類庫common

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


    網(wǎng)站導航:
     
    主站蜘蛛池模板: 国产成人aaa在线视频免费观看 | 在线a人片天堂免费观看高清| 亚洲欧美成人一区二区三区| 亚洲国产免费综合| 成人性生交大片免费看好| 亚洲综合男人的天堂色婷婷| 免费涩涩在线视频网| 中文字幕成人免费高清在线视频 | 免费jlzzjlzz在线播放视频| 黄色网站软件app在线观看免费 | 亚洲av日韩av无码| 成人免费午夜视频| 免费一级毛suv好看的国产网站| 亚洲国产成人久久综合碰碰动漫3d | 91精品国产免费入口| 国产亚洲视频在线观看网址| 亚洲爆乳无码专区| 国产无遮挡裸体免费视频| 99久久久国产精品免费牛牛四川| 亚洲精品国产首次亮相| 亚洲AV无码乱码国产麻豆穿越| 国内外成人免费视频| 国产va在线观看免费| 阿v免费在线观看| 亚洲第一网站免费视频| 亚洲色偷偷偷鲁综合| 全免费a级毛片免费看无码| 免费人妻无码不卡中文字幕系| 美女视频黄a视频全免费网站一区 美女视频黄a视频全免费网站色 | 亚洲欧美乱色情图片| 久久亚洲精品无码AV红樱桃| 亚洲日韩在线观看免费视频| 性感美女视频在线观看免费精品 | 亚洲级αV无码毛片久久精品| 噜噜嘿在线视频免费观看| 18级成人毛片免费观看| 中文字幕免费播放| 有码人妻在线免费看片| 亚洲av永久无码| 久久亚洲精品国产精品婷婷| 亚洲欧洲日产专区|