Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Renaming files from .tmp to .csv  RSS feed

 
ben rowley
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you can see below, I have created a program to write a list of Strings to a .txt file. However, rather than simply writing into a .txt file I now need to make changes so that the initial file that is created is a .tmp file and once all records have been written to that .tmp file, rename it to a .CSV file.*

Can anyone recommend how I would go about doing this?

Thanks!

 
Tim Cooke
Marshal
Posts: 3652
184
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sounds like a complete waste of time. Why not just create the file as 'csv' to begin with and save yourself the trouble?
 
ben rowley
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not my choice I'm afraid otherwise I would, Thanks for the efficient response non the less.
 
Tim Cooke
Marshal
Posts: 3652
184
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok fair enough (but still stupid). There's some methods in the File object that look like they might be useful, don't you think?

As an aside, a point of administration.
I added code tags to your post for presenting your code, see how much better it looks! (See UseCodeTags). Also, please don't use ALL CAPS in the title (or anywhere) as it comes across as very shouty.

And of course, welcome to the Ranch!
 
ben rowley
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim, I've done it now anyway- the confusion came because yeah, as you say you would normally just go ahead and write all in one go without creating the .tmp file.

About the code tags, I will play by the rules in future- I only created an account on here this morning because it seems a lot more helpful than other forums.

I just fired out that post straight away without checking out the 'UseCodeTags' or no capital letters part- I am sure I will get the hang of it

Thanks again Tim.

 
Tim Cooke
Marshal
Posts: 3652
184
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ben rowley wrote:I've done it now anyway

To give the thread some closure, and to help out the next guy who reads it, can I encourage you to share your solution?

ben rowley wrote:it seems a lot more helpful than other forums.

We do try our best.

ben rowley wrote:Thanks again Tim.

You've very welcome
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Cooke wrote:That sounds like a complete waste of time. Why not just create the file as 'csv' to begin with and save yourself the trouble?


You don't do much system-level programming, I take it.

I do this a LOT, and it's because I may be destroying an older version of a file and I want to do so in a fault-resistent way. You write out the new file, use the "move"/rename function to move the old file out of the way, then move/rename the new (tmp) file under the desired name.

My web browser downloads files with ".part" as a file suffix, then when (or if!) download is complete, removes the "part" from the filename.
 
Tim Cooke
Marshal
Posts: 3652
184
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:You don't do much system-level programming, I take it.

Guilty as charged Thanks for the education Tim.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!