1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
| import com.ewon.ewonitf.EvtWebFormListener;
import java.io.PrintStream;
import java.util.Date;
import java.util.Enumeration;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
* https://stackoverflow.com/questions/72185256/java-1-4-sort-files-recent-latest
* @author eWonSupport_Adm
*/
public class MyWebFormListener extends EvtWebFormListener
{
public void callForm(String FormName)
{
PrintStream ps = new PrintStream(this);
setWebHeader("text/plain");
// List File
if ("list".equals(FormName))
{
try
{
String FileConnStr = "file:///" + getWebVar("directory","/");
String directoryStr=getWebVar("directory","");
ps.println("directoryStr: "+directoryStr);
FileConnection fc = (FileConnection) Connector.open(FileConnStr);
if (fc.exists() && fc.isDirectory())
{
Enumeration x = fc.list();
FileConnection fc1 = null;
String sz_list = "";
String orderStr = getWebVar("order","");
String typeStr = getWebVar("type","");
String lineBreakStr = getWebVar("lineBreak","");
while(x.hasMoreElements())
{
String item = x.nextElement().toString();
fc1 = (FileConnection) Connector.open(FileConnStr+ "/" + item);
// http://192.168.0.10/rcgi.bin/jvmForm?formName=list&type=file&lineBreak=yes&order=ascending&directory=/usr
// list file
if ("file".equals(typeStr))
{
if (!fc1.isDirectory())
{
if ("yes".equals(lineBreakStr))
{
sz_list += "/" + item+ "\n";
}
else
sz_list += "/" + item + ";";
}
}
// http://192.168.0.10/rcgi.bin/jvmForm?formName=list&type=dir&lineBreak=yes&order=ascending&directory=/usr
// list dir
if ("dir".equals(typeStr))
{
if (fc1.isDirectory())
{
if ("yes".equals(lineBreakStr))
{
sz_list += "/" + item+ "\n";
}
else
sz_list += "/" + item + ";";
}
}
ps.print((sz_list));
}
else
ps.print("DIRECTORY DOES NOT EXIST");
}
catch(Exception ex)
{
System.out.println("size Command Error: " + ex.getMessage());
ps.print("list Command Error");
}
}
}
} |
Partager