With the following code I get an error that prevents compiling on the line that reads:Any idea what's up?Code:vecReturns = fileList("C:\\");
Code:import java.io.*; import java.util.*;//For the vectors public class Test { public static Vector fileList(String directoryName) throws IOException { Vector vecReturns = new Vector(); File dir = new File(directoryName); if(dir.exists() && dir.isDirectory()) { File [] list = dir.listFiles(); for (int i = 0;i<list.length;i++) { if(list[i].isFile()) { StringBuffer name = new StringBuffer(list[i].toString()); StringBuffer result = new StringBuffer(name.length()); for(int x = 0;x<name.length();x++) { if(name.charAt(x)=='\\') { result.append("\\\\"); } else { result.append(name.charAt(x)); } } //vecReturns.add(result.tostring()); vecReturns.add(result); System.out.println(result); } } return vecReturns; } else { throw new IOException(directoryName + " is not a directory."); } }//End fileList public static void main(String[] args) { Vector vecReturns = new Vector(); vecReturns = fileList("C:\\"); }//End main }//End Test


Reply With Quote
You are better off not throwing the Exception and just using a try catch structure in your method.
