java - I don't understand the program -
i wanted program list contents available in directory. found nice code in java2's.com, http://www.java2s.com/code/java/file-input-output/listingthedirectorycontents.htm
and here code,
import java.io.file; import java.util.arrays; public class dir { static int indentlevel = -1; static void listpath(file path) { file files[]; indentlevel++; files = path.listfiles(); arrays.sort(files); (int = 0, n = files.length; < n; i++) { (int indent = 0; indent < indentlevel; indent++) { system.out.print(" "); } system.out.println(files[i].tostring()); if (files[i].isdirectory()) { listpath(files[i]); } } indentlevel--; } public static void main(string args[]) { listpath(new file(".\\code")); } }
what don't understand variable n
in first for
loop. if not defined anywhere, why program not showing error?
int i, n;
would declare 2 ints.
in code
int = 0, n = files.length;
declares , initialises them.
Comments
Post a Comment