List files in a folder
import java.io.*;public static Vector
{
Vector
File folder = new File(absPathFolder);
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
System.out.println("File: " + listOfFiles[i].getName());
vectAllFiles.add(listOfFiles[i].getName() );
} else if (listOfFiles[i].isDirectory()) {
System.out.println("Directory: " + listOfFiles[i].getName());
vectAllFiles.add(listOfFiles[i].getName() );
}
}
return vectAllFiles;
}
Create folder
import java.io.*;
public static void create_new_folder(String absPathFolder)
{
File theDir = new File(absPathFolder);
// if the directory does not exist, create it
if (!theDir.exists()) {
System.out.println("creating directory: " + absPathFolder);
try{
theDir.mkdir();
} catch(SecurityException se){
se.printStackTrace();
}
}
}
{
File theDir = new File(absPathFolder);
// if the directory does not exist, create it
if (!theDir.exists()) {
System.out.println("creating directory: " + absPathFolder);
try{
theDir.mkdir();
} catch(SecurityException se){
se.printStackTrace();
}
}
}
Copy and paste files from a folder to another folder
import java.nio.file.Files;
import java.io.*;
import java.io.*;
public static void copy_paste_file(String pathCopy, String pathPaste)
{
try {
File source = new File(pathCopy);
File dest = new File(pathPaste);
Files.copy(source.toPath(), dest.toPath());
} catch (Exception e) {
e.printStackTrace();
}
}
{
try {
File source = new File(pathCopy);
File dest = new File(pathPaste);
Files.copy(source.toPath(), dest.toPath());
} catch (Exception e) {
e.printStackTrace();
}
}
Comments
Post a Comment