JPad
Snippets
Download
Help
Contact
test-listfiles
Testing to see what happens if I try to list files. Is it client-side, or server-side when it runs the script?
Code
File folder = new File("c:\\temp"); File[] listOfFiles = folder.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { System.out.println("File " + listOfFiles[i].getName()); } else if (listOfFiles[i].isDirectory()) { System.out.println("Directory " + listOfFiles[i].getName()); } }
Result
Console
File jpad.txt
Bytecode
Compiled from "RunnContainer.java" public class io.jpad.scratch.RunnContainer { public io.jpad.scratch.RunnContainer(); Code: 0: aload_0 1: invokespecial #1 // Method java/lang/Object."<init>":()V 4: return public static void main(java.lang.String...) throws java.lang.Exception; Code: 0: new #2 // class java/io/File 3: dup 4: ldc #3 // String c:\temp 6: invokespecial #4 // Method java/io/File."<init>":(Ljava/lang/String;)V 9: astore_1 10: aload_1 11: invokevirtual #5 // Method java/io/File.listFiles:()[Ljava/io/File; 14: astore_2 15: iconst_0 16: istore_3 17: iload_3 18: aload_2 19: arraylength 20: if_icmpge 110 23: aload_2 24: iload_3 25: aaload 26: invokevirtual #6 // Method java/io/File.isFile:()Z 29: ifeq 65 32: getstatic #7 // Field java/lang/System.out:Ljava/io/PrintStream; 35: new #8 // class java/lang/StringBuilder 38: dup 39: invokespecial #9 // Method java/lang/StringBuilder."<init>":()V 42: ldc #10 // String File 44: invokevirtual #11 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder; 47: aload_2 48: iload_3 49: aaload 50: invokevirtual #12 // Method java/io/File.getName:()Ljava/lang/String; 53: invokevirtual #11 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder; 56: invokevirtual #13 // Method java/lang/StringBuilder.toString:()Ljava/lang/String; 59: invokevirtual #14 // Method java/io/PrintStream.println:(Ljava/lang/String;)V 62: goto 104 65: aload_2 66: iload_3 67: aaload 68: invokevirtual #15 // Method java/io/File.isDirectory:()Z 71: ifeq 104 74: getstatic #7 // Field java/lang/System.out:Ljava/io/PrintStream; 77: new #8 // class java/lang/StringBuilder 80: dup 81: invokespecial #9 // Method java/lang/StringBuilder."<init>":()V 84: ldc #16 // String Directory 86: invokevirtual #11 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder; 89: aload_2 90: iload_3 91: aaload 92: invokevirtual #12 // Method java/io/File.getName:()Ljava/lang/String; 95: invokevirtual #11 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder; 98: invokevirtual #13 // Method java/lang/StringBuilder.toString:()Ljava/lang/String; 101: invokevirtual #14 // Method java/io/PrintStream.println:(Ljava/lang/String;)V 104: iinc 3, 1 107: goto 17 110: return }
Jpad Version:1.05
viewCount:2721
Creator:
mellamokb
Latest Editor:
mellamokb
Tags
java
files
Download
Copy As Markdown:
**code [test-listfiles.java](/example/1w/test-listfiles)** File folder = new File("c:\\temp"); File[] listOfFiles = folder.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { System.out.println("File " + listOfFiles[i].getName()); } else if (listOfFiles[i].isDirectory()) { System.out.println("Directory " + listOfFiles[i].getName()); } } **Result:** File jpad.txt