Rename a file: Difference between revisions
Content added Content deleted
No edit summary |
m (→{{header|Java}}: several misspellings) |
||
Line 226: | Line 226: | ||
// Rename file (or directory) |
// Rename file (or directory) |
||
boolean success = file.renameTo(file2); |
boolean success = file.renameTo(file2); |
||
return |
return success; |
||
} |
} |
||
public static void test(String type, String oldname, String newname) { |
public static void test(String type, String oldname, String newname) { |
||
Line 236: | Line 236: | ||
public static void main(String args[]) { |
public static void main(String args[]) { |
||
test("file", "input.txt", "output.txt"); |
test("file", "input.txt", "output.txt"); |
||
test("file", File. |
test("file", File.separator + "input.txt", File.separator + "output.txt"); |
||
test("directory", "docs", "mydocs"); |
test("directory", "docs", "mydocs"); |
||
test("directory", File. |
test("directory", File.separator + "docs" + File.separator, File.separator + "mydocs" + File.separator); |
||
} |
} |
||
}</lang> |
}</lang> |