Sponsors: Michael Fertik - Best JAVA Web hosting Company & 30% off


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-22-2010, 08:00 AM
Member
 
Join Date: Mar 2009
Posts: 48
Rep Power: 0
doha786 is on a distinguished road
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 ?
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.
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
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 03-22-2010, 08:25 AM
Senior Member
 
Join Date: Jun 2008
Posts: 1,622
Rep Power: 4
masijade is on a distinguished road
Default
Change your code to use String concatenation in that spot?

i.e.
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 03-22-2010, 08:55 AM
Member
 
Join Date: Mar 2009
Posts: 48
Rep Power: 0
doha786 is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
save file based on file extension masa AWT / Swing 4 05-11-2010 11:17 AM
how to save Interface (file extension) shaggyoo7 New To Java 9 01-10-2009 09:07 AM
File Extension Filter heartysnowy New To Java 6 11-26-2008 12:41 PM
How to make delete particular extension file from a directory Java Tip java.io 0 04-05-2008 10:13 AM
Regex for file extension gapper New To Java 1 01-31-2008 03:59 PM


Java Forums is supported by the best jsp hosting.

All times are GMT +2. The time now is 05:57 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org