Is there a better way to sort this, to get the correct order? Thanks
import java.io.*;
import java.util.*;
public class JpgDirToHtm
{
public static void main(String[] args) throws FileNotFoundException
{
Scanner kb = new Scanner(System.in);
System.out.print("Enter the path of the folder whose contents you wish to insert into an html file: ");
String path = kb.nextLine();
File folder = new File(path);
File[] listOfFiles = folder.listFiles();
ArrayList<String> htmlTextList = new ArrayList<String>();
for (int i = 0; i < listOfFiles.length; i++)
{
if (listOfFiles[i].isFile())
{
htmlTextList.add(listOfFiles[i].getName() );
}
}
Collections.sort(htmlTextList);
System.out.println(htmlTextList);
}
}
This is what it prints [1.jpeg, 10.jpg, 11.jpeg, 12.jpeg, 13.jpeg, 14.jpeg, 16.jpg, 17.jpg, 18.jpg, 19.jpg, 2.jpeg, 20.jpg, 21.jpg, 22.jpg, 23.jpg, 24.jpg, 25.jpg, 3.jpg, 5.jpg, 7.jpeg, 9.jpg]
I need 2.jpeg to come after 1.jpeg et cetera.
Sorry, there is probably a simple fix but I haven't found anything on google. I am new to programming.
Everything else works really well. The whole program can take thousands of photos and automatically place them, sized correctly, in html web pages at a given number of photos per page that you can set. If any one is interested in having the rest of the code I will post it.