• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

new file creation

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
try this code (untested):

cu
Stefan
 
rahul saxena
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i don't have a sample, i was only suggesting mods to your code snippet:
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps someone may move this to the IO Forum?
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good idea, Stefan.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic