?
Solved

Adding distinct filenames to a string array

Posted on 2003-03-26
8
Medium Priority
?
185 Views
Last Modified: 2010-03-31
Hi there
I have a folder which i want to add the contents of it to a string array. However some of the files have the same name but a different file extension eg foo.txt and foo.zip
I have being using
File fileList = new File(path);
String[] projects = fileList.list();

but it is no use anymore as it shows two files instead of one. I just want one entry of each  distinct filename in the string array. Ive being trying to use a filefilter but to na avail. Your help is appriciated.
 
0
Comment
Question by:illumin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 3

Expert Comment

by:schybert
ID: 8210623
I'm confused... you don't want to show all the files in the directory? foo.zip and foo.txt are after all distinct file names...
0
 

Author Comment

by:illumin
ID: 8210663
Ok ill try to explain it better... I have two files in a dir called foo.txt and foo.zip .I only want to add one foo to the string array instead of two. The code that ive come up with so far still shows up two foo's :(

package mypackage;
import java.io.*;

public class ZipFilter implements FilenameFilter
{  
  public boolean accept(File dir,String name)
   {  
    return(name.endsWith(".zip"));
   }
}

String path = (String)session.getAttribute("Path");
  File fileList = new File(path);
  ZipFilter filter = new ZipFilter();
  fileList.list(filter);
0
 

Author Comment

by:illumin
ID: 8210693
String[] projects = fileList.list(); should be on the end of the las comment
The second block of code is in a different class :P
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:illumin
ID: 8210730
Sorry i am so stupid i was doing this
String[] projects = fileList.list();

instead of this

 String[] projects = fileList.list(filter);

It works fine for me now ...
0
 
LVL 3

Expert Comment

by:schybert
ID: 8210992
hehe, great
0
 

Author Comment

by:illumin
ID: 8211048
Can any mods delete this question please
0
 

Expert Comment

by:CleanupPing
ID: 9058474
illumin:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 9061362
User resolved; points refunded and question closed.

Netminder
EE Admin
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question