Al momento, stai seguendo questa domanda
- Vedrai gli aggiornamenti nel tuofeed del contenuto seguito.
- Potresti ricevere delle e-mail a seconda delle tuepreferenze per le comunicazioni.
How specific lines in a text file can be updated many times ?
Risposta accettata
21 Commenti
- create a new file each time, preserving the previous ones, leaving it for the user to clean them up as desired
- create a new file, rename the old file to ".bak" (or similar), rename the new file to the old name; in this way if the new file creation fails, there is always the .bak to go back to
- create a new file, rename it to the old name once it is fully created; keeping a backup like the above would be better, but at the very least, do not put the new file into the place of the old file until the new file has been completely created and verified to have worked
- in cases where preserving file dates and permissions (and alternative resource forks) is important and those cannot be easily copied from one file to another, then create a new file, write the data to it, verify it is all correct, then take the contents and use them to overwrite the old file in-place (because overwriting preserves dates and access permissions and resource forks.) In this set-up, there is always a file with valid data contents in existence in case something goes wrong while overwriting the file. Note: you cannot reliably do this in MATLAB, because MATLAB does not allow you to truncate existing files if they should shrink due to the new content being smaller
- in the more general case, use a "transactional database" that is able to roll-back failed or incomplete transactions; or if your file-system supports transactions (for example the native Mac OS-X file system does), find a way to make the update take only a single transaction for file-system purposes so that you can recover if something goes wrong.
Più risposte (0)
Vedere anche
Categorie
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Si è verificato un errore
Impossibile completare l'azione a causa delle modifiche apportate alla pagina. Ricarica la pagina per vedere lo stato aggiornato.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.
Americhe
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia-Pacifico
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)