Get The list of all file name from directory/folder and store into string array in java
import java.io.FileReader ;
import java.io.File ;
import java.io.FileNotFoundException ;
import java.io.IOException ;
import java.util.ArrayList ;
class GetFileFromFolder {
public String[] listOfFiles() {
String pathLevel = "/home/brij/brijJava";
File file = new File(pathLevel);
String[] levelNames = file.list();
return levelNames;
}
public static void main(String arg[]) {
GetFileFromFolder obj = new GetFileFromFolder();
String[] allFile = obj.listOfFiles();
for (int i = 0; i < allFile.length; i++) {
System.out.println("File Name " + allFile[i]);
}
}
}
Now compile this from command line
For compile
javac GetFileFromFolder.java
For execute
java GetFileFromFolder
File Name GetFileFromFolder.java
File Name GetFileFromFolder.java~
File Name GetFileFromFolder.class
File Name sql
File Name 25-11-17
import java.io.FileReader ;
import java.io.File ;
import java.io.FileNotFoundException ;
import java.io.IOException ;
import java.util.ArrayList ;
class GetFileFromFolder {
public String[] listOfFiles() {
String pathLevel = "/home/brij/brijJava";
File file = new File(pathLevel);
String[] levelNames = file.list();
return levelNames;
}
public static void main(String arg[]) {
GetFileFromFolder obj = new GetFileFromFolder();
String[] allFile = obj.listOfFiles();
for (int i = 0; i < allFile.length; i++) {
System.out.println("File Name " + allFile[i]);
}
}
}
Now compile this from command line
For compile
javac GetFileFromFolder.java
For execute
java GetFileFromFolder
File Name GetFileFromFolder.java
File Name GetFileFromFolder.java~
File Name GetFileFromFolder.class
File Name sql
File Name 25-11-17
No comments:
Post a Comment