如果在windows下,系统规定文件名不能有":" 所以不能实现

解决方案 »

  1.   

    程序如下,只是将:改为.import java.io.*;
    import java.text.*;
    import java.util.*;
    /**
     * 用当前时间作为文件名
     */
    public class TestFileSave {    public static void main(String argv[]) {
            new TestFileSave();
        }    public TestFileSave() {        String    currFileName = null;        // Handle the case where we don't have a file name yet.
            if( currFileName == null ) {
                Date iNow = new Date();
                SimpleDateFormat iFormat = new SimpleDateFormat( "yyyy-MM-dd HH.mm.ss" );
                currFileName = iFormat.format( iNow );
            }        try {
                // Open a file of the current name.
                File file = new File( currFileName );            // Create an output writer that will write to that file.
                // FileWriter handles international characters encoding conversions.
                FileWriter out = new FileWriter( file );
                String text = "Hello World";
                out.write( text );
                out.close();            // Display the name of the saved directory+file in the statusBar.
                System.out.println( currFileName );
            }
            catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
      

  2.   

    我想用空件,
    来触发它,
    这样有main好像不能放在空件中来触发吧,
    它是自动的来保存吗?
    好像你的程序中没有选保存的路径呀,
    那程序知道保存到哪里吗?
      

  3.   

    谢谢你,
    typet1998() 
    我成功了,
    我该怎么把,文件名后面加个".txt"呀!
    你在就给我会答呀!
    过会我会加分的,
    谢谢
      

  4.   

    File file = new File( currFileName + ".txt");
      

  5.   

    对不起,
    bobokong(寻找编程的乐趣) 你来晚了,谢谢你呀
    我加完分,你就来了,
    下次我会补分给你的,(在我下次的问题中)
    好,
    不好意思,