user3343424
user3343424

Reputation:

Find specific file

I want capture a specific file name and the easiest way I found was using a class called JavaXT, based on examples of official site (http://www.javaxt.com/javaxt-core/io/Directory/Recursive_Directory_Search) I tried return the result in my console application across

javaxt.io.Directory directory = new javaxt.io.Directory("/temp");
javaxt.io.File[] files;

//Return a list of PDF documents found in the current directory and in any subdirectories
files = directory.getFiles("*.pdf", true);

System.out.println(files);

But the returned value always are strange characters like [Ljavaxt.io.File;@5266db4e

Someone could help me to print the correct file(s) name?

Upvotes: 0

Views: 112

Answers (2)

Christian Tapia
Christian Tapia

Reputation: 34146

When you try to print an array, what you get is its hashcode. Try this if you want to visualize it:

 Integer[] a = { 1, 2, 3 };
 System.out.println(a);

the output will be

[Ljava.lang.Integer;@3244331c

If you want to print element by element, you can iterate through the array. In this case, using a for-each:

for (javaxt.io.File f : files)
    System.out.println(f);

Note that this will print the String returned by the method toString() of the object.

Upvotes: 1

nimsson
nimsson

Reputation: 950

Your files variable is an array. You need

for(javaxt.io.File f:files) System.out.println(f);

Because files is an array, Java will print the array type and the hex hash code.

Upvotes: 1

Related Questions