Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2004
    Messaggi
    181

    [java] spostare un file direttamente

    salve

    avrei bisogno di spostare un file da una cartella ad un'altra, esiste un comando che permette questa operazione?

    ho già cercato nel forum, e ho trovato un thread simile, ma la risposta, a mio parere non soddisfava la domanda, infatti spiegava come "rinominare" un file e non spostarlo.. o mi sbaglio? "renameTo ()" serve per lo spostamento?

    qualcuno ha qualche vaga idea?

    chessò tipo "moveTo()", boh..
    grazie!
    -- John --

  2. #2
    Utente di HTML.it
    Registrato dal
    Jan 2004
    Messaggi
    181
    vi prego, so che siete bravi quando volete.. almeno per piecere ditemi se può bastare "renameTo()"

    Grazie mille!
    -- John --

  3. #3
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284

    Re: [java] spostare un file direttamente

    Originariamente inviato da McLain
    salve

    avrei bisogno di spostare un file da una cartella ad un'altra, esiste un comando che permette questa operazione?

    ho già cercato nel forum, e ho trovato un thread simile, ma la risposta, a mio parere non soddisfava la domanda, infatti spiegava come "rinominare" un file e non spostarlo.. o mi sbaglio? "renameTo ()" serve per lo spostamento?
    Sì, può servire anche per spostare un file.

    Esempio su Windows:
    codice:
    File src = new File ("C:\\WINNT\\Rododendro.bmp");
    
    File dest = new File ("C:\\TEMP\\Rododendro.bmp");
    
    if (src.renameTo (dest))
        System.out.println ("OK");
    else
        System.out.println ("ERRORE");
    Sposta l'immagine Rododendro.bmp dalla directory di Windows alla directory temporanea.

    Comunque, nota bene, la documentazione di renameTo() dice:

    Many aspects of the behavior of this method are inherently platform-dependent: The rename operation might not be able to move a file from one filesystem to another, it might not be atomic, and it might not succeed if a file with the destination abstract pathname already exists. The return value should always be checked to make sure that the rename operation was successful.
    Andrea, andbin.devSenior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    java.util.function Interfaces Cheat SheetJava Versions Cheat Sheet

  4. #4
    Utente di HTML.it
    Registrato dal
    Jan 2004
    Messaggi
    181
    ko andrea,
    intanto grazie
    -- John --

  5. #5
    Moderatore di Programmazione L'avatar di alka
    Registrato dal
    Oct 2001
    residenza
    Reggio Emilia
    Messaggi
    24,477

    Moderazione

    Attenzione che la sezione sia corretta... sposto nel forum dedicato a Java.
    MARCO BREVEGLIERI
    Software and Web Developer, Teacher and Consultant

    Home | Blog | Delphi Podcast | Twitch | Altro...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.