• 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:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Checking for a Modified File

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an homework organizing application in which you can save you assignments to a file. I want to be able to, when the users exits, and if the document is modified, prompt to save changes or not. How would I go about calling a function to do this on a person choosing to close (I would know how if they chose 'Exit' from the menu, but I would like to know how to if they choose to click the "X" to close) Also I would like to know the most efficient way of doing this. I was thinking about containing a hash of the information in the file and when exit is chosen compare the hash of the new data to the old. What would you suggest, and how, if hashing is the best idea, would I go about that? Would reading the information into a stream and then hashing the stream be the best, or creating a temporary file and hashing it be the best way. Thank you for your time and GOD Bless.

Matthew Middleton
 
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about setting a modified flag if the user takes any action that modifies the file? Then, if the flag is true, save the file.
 
Matthew Middleton
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thats another idea I was thinking about, every time you press the next or previous buttons to browse the entries, the values are saved to variable. I was thinking about when you press either button, check to see if the new value is different, setting the flag to true (that the file is modified). I was wondering if I doing those comparisons would be best put into a thread.
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why would you put them into a thread of their own?

Unless you have some complex action to take on it becoming known a file has been modified (but not yet saved) it's not needed.
If it is, a notification event queue is the best way where you can indeed have a thread read the queue, but this is likely overly complex.
A Map of Booleans (with an entry per opened file) is far simpler.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic