Results 1 to 3 of 3
  1. #1
    doha786 is offline Member
    Join Date
    Mar 2009
    Posts
    48
    Rep Power
    0

    Default how to create New file with specified file extension ?

    hi,
    here is the code that can able to create new file in my desired folder. Now what should i do if want to separate the file extension while using createNewFile() method ?
    Java Code:
    try{
    File directory = new File("C:/Java/mydir");
    directory.mkdirs();
     
    File f = new File(directory, "info.txt");
    f.createNewFile();
    }
    suppose, to create temp file, it has a method to separate the file extension.
    Java Code:
    File file = File .createTempFile( "info", ".txt", new File( "C:\\Java" ) );
    have any method like this for createNewFile() method ??
    what we are thinking, it might not be true

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Change your code to use String concatenation in that spot?

    i.e.
    Java Code:
    File f = new File(directory, "info" + ".txt");
    Edit: This is, afterall, essentially what createTempFile does (although it might create the name in a String var, then use that single String var, the principle is the same). It also uses "prefix" + "oneUpNumberNormally" + "suffix", but that is simply taking it one step further.
    Last edited by masijade; 03-22-2010 at 08:34 AM.

  3. #3
    doha786 is offline Member
    Join Date
    Mar 2009
    Posts
    48
    Rep Power
    0

    Default

    thanks a lot....

    actually i was looking for this information that u made clear, really appreciate you
    what we are thinking, it might not be true

Similar Threads

  1. File Extension Filter
    By heartysnowy in forum New To Java
    Replies: 9
    Last Post: 10-09-2010, 01:33 PM
  2. save file based on file extension
    By masa in forum AWT / Swing
    Replies: 4
    Last Post: 05-11-2010, 11:17 AM
  3. how to save Interface (file extension)
    By shaggyoo7 in forum New To Java
    Replies: 9
    Last Post: 01-10-2009, 09:07 AM
  4. Replies: 0
    Last Post: 04-05-2008, 10:13 AM
  5. Regex for file extension
    By gapper in forum New To Java
    Replies: 1
    Last Post: 01-31-2008, 03:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •