Import Java.io.File;
Import java.io.FileNotFoundException;
Import Java.io.FileWriter;
Import java.io.IOException;
public class Takefilepathandname {public static void main (string[] args) throws filenotfoundexception{
This is the path where the file ' s name you want to take.
String path = "D:\\10stanford 100";
File File = new file (path);
file[] array = File.listfiles ();
String s = null;
for (int i =0;i< array.length;i++) {try {s = "d:\\stanford\\" +array[i].getname () + ". txt";
File File1 = new file (s);
File1.createnewfile ();
catch (IOException e) {//TODO automatically generated catch block E.printstacktrace (); } getFile (Array[i].getpath (), s); Gets the file path under the root directory} private static void GetFile (String path,string s) {//Get file list wh
Ere the path has//Get the folder List file File1 = new file (path); file[] array = File1.listfiles ();
try {FileWriter output = new FileWriter (s); for (int i=0;i<array.length;i++) {if (Array[i].isfile ()) {//system.out.println (array[i].getn
Ame ());
Output.append (Array[i].getname ());//Add in file (picture) name} output.close ();
catch (IOException e) {//TODO automatically generated catch block E.printstacktrace ();
}
}
}
because of some needs, you need to read all the file names of subfolders under the folder and save them in txt format as a file name
Input:
Output: