Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

new file creation  RSS feed

 
rahul saxena
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
I have generated pdf file. I have to rename tht file and send as attachment in mail. problem here is its renaming and sending mail with renamed file as attachment but i am not able to find renamed file in local system.
Also sometimes its very inconsistent , its giving "File not found Exception"(for previous file name)
please see the following code....
String filename = "C:\\test2222.txt";
FileDataSource fds = new FileDataSource(filename);
File file = fds.getFile();
if ( file.exists() ) {
File file1 = new File(filename);
file1.renameTo(new File("05012004.txt"));
}
can u please tell me how to make copy of original file and then renaming that file with new name? will this solve my problem?
thanks in advance..
 
Stefan Krompass
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
try this code (untested):

cu
Stefan
 
rahul saxena
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stefan Krompass,
thanks for timely response. I am using same logic, it working fine but sometimes it cribs and I cant predict when it will give "file not found exception". but intrestingly old file will be there in local system.
Is it bcoz its trying to access file before its getting generated? It should not bcoz we are checking for oldFile.exists() condition. and also why i am not able to find newly named files? but attachments are going in mail with newname
Will it solve If I give delay of few seconds before attaching files ?
regards,
Shankar
 
clio katz
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just a suggestion but:
(1) i'm not sure what FileDataSource class is doing, but I don't see why it should not have to relinquish it's file handle *before* you rename the file it has fetched for you... Will it not generate a FileNotFoundException sooner-or-later when it shuts-down/goes out of scope?
(2) i don't see anywhere that you give a (fully-qualified) filepath for the renamed file ... presumably it will be written to the 'current' directory - whatever that may be ... it may be better to give it an explicit path - at least you'll know where to look for it:-)
hth
 
senthil doraiswamy
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its a good practice to check the return value (boolean type) of the renameTo method to conclude whether it performed the operation successfully or not. i had this issue when i tried to rename a file from one file system to another (equalent to unix "mv"), the return code i got was "false".
 
rahul saxena
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
thanks for the response. Do u have any sample program for creating copy of .pdf file?
thanks in advance.

Originally posted by clio cat:
just a suggestion but:
(1) i'm not sure what FileDataSource class is doing, but I don't see why it should not have to relinquish it's file handle *before* you rename the file it has fetched for you... Will it not generate a FileNotFoundException sooner-or-later when it shuts-down/goes out of scope?
(2) i don't see anywhere that you give a (fully-qualified) filepath for the renamed file ... presumably it will be written to the 'current' directory - whatever that may be ... it may be better to give it an explicit path - at least you'll know where to look for it:-)
hth
 
clio katz
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i don't have a sample, i was only suggesting mods to your code snippet:
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps someone may move this to the IO Forum?
 
Marilyn de Queiroz
Sheriff
Posts: 9079
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good idea, Stefan.
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by shankar cool:

Do u have any sample program for creating copy of .pdf file?

Answered in the
Other Java API's Forum.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!