S
subhabangalore
Dear Group,
I am taking out the files in my desktop folder, as,
File folder = new File("C:\\Users\\subhabrata\\Desktop");
Next, I am trying to take them out one by one as using for loop and name
of each file is converted to String,
for( File name :folder.listFiles()){
String s1=name.toString();
System.out.println("####"+s1);
System.out.print( name );
}
Till this there is no issue, now I am trying to insert name of all the files in an array, generally it can be done, as,
ArrayList<String> myList = new ArrayList<String>();
myList.add(s1);
But the problem I am facing is, if I put it as,
for( File name :folder.listFiles()){
String s1=name.toString();
System.out.println("####"+s1);
System.out.print( name );
ArrayList<String> myList = new ArrayList<String>();
myList.add(s1);
}
I am getting name of files individually but I want to see them as the whole bunch like,
myList=["string1","string2","string3",...."StringN"]
My aim is to check the names then in another for loop and if match is not found with some defined name update the list.
I am slightly new in Java so if anyone can kindly suggest how I should address it.
Regards,
Subhabrata.
I am taking out the files in my desktop folder, as,
File folder = new File("C:\\Users\\subhabrata\\Desktop");
Next, I am trying to take them out one by one as using for loop and name
of each file is converted to String,
for( File name :folder.listFiles()){
String s1=name.toString();
System.out.println("####"+s1);
System.out.print( name );
}
Till this there is no issue, now I am trying to insert name of all the files in an array, generally it can be done, as,
ArrayList<String> myList = new ArrayList<String>();
myList.add(s1);
But the problem I am facing is, if I put it as,
for( File name :folder.listFiles()){
String s1=name.toString();
System.out.println("####"+s1);
System.out.print( name );
ArrayList<String> myList = new ArrayList<String>();
myList.add(s1);
}
I am getting name of files individually but I want to see them as the whole bunch like,
myList=["string1","string2","string3",...."StringN"]
My aim is to check the names then in another for loop and if match is not found with some defined name update the list.
I am slightly new in Java so if anyone can kindly suggest how I should address it.
Regards,
Subhabrata.