File filex=new File("c://1.avi");
URL movieUrl =null;

try
{
movieUrl = filex.toURL();
System.out.println(movieUrl);
} catch (MalformedURLException e3)
{
// TODO 自动生成 catch 块
e3.printStackTrace();
}
我将这个执行,为什么没有在C盘下生成相应的文件啊?

解决方案 »

  1.   


    import java.io.*;public class Test{
       public static void main(String [] args){
           File filex=null;
           URL movieUrl =null; 
           try 
           { 
            filex = new File("C:\\jpanseAV.avi");
            movieUrl = filex.toURL();        } catch (Exc) 
           { 
             // TODO 自动生成 catch 块 
              e3.printStackTrace(); 
           } 
       }
    }
      

  2.   


      /*
     * $RCSfile: Test.java,v $
     * $Revision: 1.1  $
     * $Date: 2009-2-28  $
     *
     * Copyright (C) 2005 Bettem, Inc. All rights reserved.
     *
     * This software is the proprietary information of Bettem, Inc.
     * Use is subject to license terms.
     */package test;import java.io.File;
    import java.io.IOException;
    /**
     * <p>Title: Test</p> 
     * <p>Description: </p> 
     * <p>Copyright: Copyright (c) 2006</p> 
     * @author lihan
     * @version 1.0
     */public class Test { /**
     * @param args
     */
    public static void main(String[] args) {
    File file = new File("c:lihan.txt");
    if(!file.exists())
    {
    try {
    file.createNewFile();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    }}
      

  3.   

    File 只是一个文件描述符。并不会对文件内容产生操作。FileOutputStream FileInputStream是对文件的写入和读取。createNewFile是创建新的文件,当然,如果以前存在,则被重写了,这个要注意!
      

  4.   

    参考这个看看
    JAVA的文件追加写入操作测试
      

  5.   

    创建文件需要写操作File file = new File("c:lihan.txt");
            if(!file.exists())
            {
                try {
                    file.createNewFile();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }