Click here to watch in Youtube :
https://www.youtube.com/watch?v=zITbu5UKZ7Q&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Java Tutorial : Java IO (Java File - How to rename a file or How to move a file to another dir) |
import java.io.File; /* * public boolean renameTo(File dest) * * Parameters: * ---------- * * dest - The new abstract pathname for the named file */ public class FileDemo1 { public static void main(String[] args) { File file = new File("D:/work/myfile.txt"); /* * Renames the file denoted by this abstract * pathname. * * Returns: true if and only if the renaming * succeeded; false otherwise */ boolean success = file.renameTo(new File("D:/work/java.txt")); System.out.println("success = " + success); } }
success = trueFileDemo2.java
import java.io.File; /* * public boolean renameTo(File dest) * * Parameters: * ---------- * * dest - The new abstract pathname for the named file */ public class FileDemo2 { public static void main(String[] args) { File file = new File("D:/work/myfile.txt"); /* * Renames the file denoted by this abstract * pathname. * * Returns: true if and only if the renaming * succeeded; false otherwise */ boolean success = file.renameTo(new File("D:/work/misc/java.txt")); System.out.println("success = " + success); } }
success = trueClick the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/JavaIODemo_File_rename_App.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/JavaIODemo_File_rename_App
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/882ffbbbc9c8fbb765fb4869059bc3ee253ad31b/BasicJava/JavaIODemo_File_rename_App/?at=master
See also:
No comments:
Post a Comment