import java.nio.file.Paths;
import java.nio.file.Path;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.io.IOException;
public class Manipulate{
public static void main(String[] args){
try{
Path pathObject = Paths.get("/home/codio/workspace/file.txt");
/* -=-=-=-=- MORE CODE GOES HERE -=-=-=-=- */
}catch(InvalidPathException e){
//cannot convert string to path
System.out.println("Error: Invalid Path");
return;
}catch(IOException e){
//file system error
System.out.println("Error: IOException");
return;
}
}
}
import java.nio.file.Paths;
import java.nio.file.Path;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.io.IOException;
public class Manipulate{
public static void main(String[] args){
try{
Path pathObject = Paths.get("/home/codio/workspace/file.txt");
/* -=-=-=-=- MORE CODE GOES HERE -=-=-=-=- */
}catch(InvalidPathException e){
//cannot convert string to path
System.out.println("Error: Invalid Path");
return;
}catch(IOException e){
//file system error
System.out.println("Error: IOException");
return;
}
}
}
import java.nio.file.Paths;
import java.nio.file.Path;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.io.IOException;
public class Manipulate{
public static void main(String[] args){
try{
Path pathObject = Paths.get("/home/codio/workspace/file.txt");
/* -=-=-=-=- MORE CODE GOES HERE -=-=-=-=- */
}catch(InvalidPathException e){
//cannot convert string to path
System.out.println("Error: Invalid Path");
return;
}catch(IOException e){
//file system error
System.out.println("Error: IOException");
return;
}
}
}
import java.nio.file.Paths;
import java.nio.file.Path;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.io.IOException;
public class Manipulate{
public static void main(String[] args){
try{
Path pathObject = Paths.get("/home/codio/workspace/file.txt");
/* -=-=-=-=- MORE CODE GOES HERE -=-=-=-=- */
}catch(InvalidPathException e){
//cannot convert string to path
System.out.println("Error: Invalid Path");
return;
}catch(IOException e){
//file system error
System.out.println("Error: IOException");
return;
}
}
}
import java.nio.file.Paths;
import java.nio.file.Path;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.io.IOException;
public class Manipulate{
public static void main(String[] args){
try{
Path pathObject = Paths.get("/home/codio/workspace/file.txt");
/* -=-=-=-=- MORE CODE GOES HERE -=-=-=-=- */
}catch(InvalidPathException e){
//cannot convert string to path
System.out.println("Error: Invalid Path");
return;
}catch(IOException e){
//file system error
System.out.println("Error: IOException");
return;
}
}
}
import java.nio.file.Paths;
import java.nio.file.Path;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.io.IOException;
public class Manipulate{
public static void main(String[] args){
try{
Path pathObject = Paths.get("/home/codio/workspace/file.txt");
/* -=-=-=-=- MORE CODE GOES HERE -=-=-=-=- */
}catch(InvalidPathException e){
//cannot convert string to path
System.out.println("Error: Invalid Path");
return;
}catch(IOException e){
//file system error
System.out.println("Error: IOException");
return;
}
}
}
//Determine if a file or directory
//exists at that path
Files.exists(pathObject);
//Is that object a directory?
Files.isDirectory(pathObject);
//Is that object a regular file?
Files.isRegularFile(pathObject);
Files.size(pathObject);
Returns size of file in bytes
Throws IOException on a directory
or missing file
Path source = Paths.get("/home/codio/workspace/dir1/file1.txt");
Path dest = Paths.get("/home/codio/workspace/dir2/file2.txt");
//copy file
Files.copy(source, dest);
//move (rename) file
Files.move(source, dest);
Will throw FileAlreadyExistsException
if destination exists
We can tell it to overwrite
(see documentation)
Files.delete(pathObject);
Will throw DirectoryNotEmptyException
if deleting a non-empty directory
Files.createFile(pathObject);
Files.createDirectory(pathObject);
Will throw FileAlreadyExistsException
if destination exists