Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx01.iad01.newshosting.com!newshosting.com!news-out.readnews.com!transit3.readnews.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: A strange behaviour of a File property Date: Fri, 11 Nov 2011 07:34:50 -0800 (PST) Organization: http://groups.google.com Lines: 61 Message-ID: <2735801.801.1321025690138.JavaMail.geo-discussion-forums@prdy11> References: <5980efbc-9010-4145-b886-fe106c5ac2d5@c18g2000yqj.googlegroups.com> Reply-To: comp.lang.java.programmer@googlegroups.com NNTP-Posting-Host: 173.164.137.214 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1321025690 3159 127.0.0.1 (11 Nov 2011 15:34:50 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 11 Nov 2011 15:34:50 +0000 (UTC) In-Reply-To: <5980efbc-9010-4145-b886-fe106c5ac2d5@c18g2000yqj.googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=173.164.137.214; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T User-Agent: G2/1.0 X-Google-Web-Client: true Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:9848 ale...@inwind.it wrote: > I've written this toy-code to test the funcionality of the File class > and I've found a strange behaviour. > My code works only with the dot directory (the directory where the > Main.class is contained) and it doesn't with any other. What's the > problem? What *precisely* are the symptoms when it doesn't work, and what values other than "." have you tried? It's difficult to help when you're vague about the problem. > here is the code > > > > import java.io.*; > > public class Main { > public static void main(String[] args){ > File f = new File("."); // try to change the path DO NOT INDENT USENET POSTS WITH TAB CHARACTERS! If you're asking the world of strangers to help, please do try to make it easy to read your code. Use spaces to indent, up to four per level. > File[] file_array = null;' > String[] content = null; > content = f.list(); Why not 'String[] content = f.list();'? Extra asssignments to 'null' are not helpful. > file_array = new File[content.length]; > boolean[] bool_array1 = new boolean[content.length]; > boolean[] bool_array2 = new boolean[content.length]; > > for(int i=0; i > file_array[i] = new File("." + "\\" + content[i]); Does 'content[i]' contain what you expect? > bool_array1[i] = file_array[i].isDirectory(); > bool_array2[i] = file_array[i].isFile(); This value is not used? > System.out.println(content[i] + "\tis a directory?: " + > bool_array1[i]); > } > } > > } What are your outputs in the scenario that "works" (and what does "works" mean?) and in the scenario that doesn't? -- Lew