Results 1 to 3 of 3
- 03-22-2010, 08:00 AM #1
Member
- Join Date
- Mar 2009
- Posts
- 48
- Rep Power
- 0
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 ?
suppose, to create temp file, it has a method to separate the file extension.Java Code:try{ File directory = new File("C:/Java/mydir"); directory.mkdirs(); File f = new File(directory, "info.txt"); f.createNewFile(); }
have any method like this for createNewFile() method ??Java Code:File file = File .createTempFile( "info", ".txt", new File( "C:\\Java" ) );
what we are thinking, it might not be true
- 03-22-2010, 08:25 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Change your code to use String concatenation in that spot?
i.e.
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.Java Code:File f = new File(directory, "info" + ".txt");
Last edited by masijade; 03-22-2010 at 08:34 AM.
- 03-22-2010, 08:55 AM #3
Member
- Join Date
- Mar 2009
- Posts
- 48
- Rep Power
- 0
Similar Threads
-
File Extension Filter
By heartysnowy in forum New To JavaReplies: 9Last Post: 10-09-2010, 01:33 PM -
save file based on file extension
By masa in forum AWT / SwingReplies: 4Last Post: 05-11-2010, 11:17 AM -
how to save Interface (file extension)
By shaggyoo7 in forum New To JavaReplies: 9Last Post: 01-10-2009, 09:07 AM -
How to make delete particular extension file from a directory
By Java Tip in forum java.ioReplies: 0Last Post: 04-05-2008, 10:13 AM -
Regex for file extension
By gapper in forum New To JavaReplies: 1Last Post: 01-31-2008, 03:59 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks