Java.io.file.list(FileFilter) problem

When I add the following filter within the parentheses of the .list() method, I get a "cannot resolve symbol" error. It seems odd to me that all of a sudden the classpath needs to be different because I add this (unless I am mistaken as to the solution.
BTW, I am using Sun ONE Studio 4 update 1. I can't figure out how to change the classpath for the project within the GUI anyway.
Thanks,
LNMEgo
        String [] files = filePath.list(
  new FileFilter()
     public boolean  accept(File file)
        if (file.isDirectory()) return false; // ignore if this is a directory
        String fileName = file.getName();//.toUpperCase; // get the name of the file in upper case
        if (fileName.endsWith(".TXT")) return true; // if it ends with .TXT, then accept it
        return false; // otherwise, ignore it
        );

Hehe, you've danced around the solution/problem
Check out the methods defined in the API
String[] list()
String[] list(FilenameFilter filter)
File[] listFiles()
File[] listFiles(FileFilter filter)
File[] listFiles(FilenameFilter filter)
You're trying to use a FileFilter, and return a String[].... look more closely.
Either use a FilenameFilter and get your String[], or continue with the FileFilter, and receive a File[].
Good luck,
Radish21

Similar Messages

  • Static lookup lists:read data from a Java *.properties file

    Hi
    i need to make static lookup lists i am using read data from a Java *.properties file
    i am using the Class "PropertyFileBasedLookupViewObjectImpl" that wrote by Steve Muench in ToyStore.
    but i need to use the default language for that i update the loadDataFromPropertiesFile()
    method to find the correct properties file
    String temp=Locale.getDefault().getLanguage();
    String propertyFile =
    getViewDef().getFullName().replace('.', '/')+"_"+temp+ ".properties";
    the problem:
    For English(TEST_en.properties) it is good and working
    For Arabic(TEST_ar.properties) read from correct file _ar.properties
    but the dispaly character is wrong
    When Debug
    In the File 1=دمشق
    In debug 1=/u32423

    Depending on your use case you can either use a programmatic VO or directly expose the JV class as a data control.
    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_36/jdtut_11r2_36.html

  • java.io.File instance .list() not working properly

    i want to get the file, folders in any directory, so i used the File.list() method.
    but it is working in a peculiar manner. first see my simplified code, where the problem i am having::
    public class FileChildTest {
         public static void main(String[] args) {
              try{
                   String[] s=new java.io.File(args[0]).list();
                   for (int i = 0; i<s.length; i++){
                        System.out.println (s);
              catch(java.lang.Exception ex){
    now, say i saved it in c:\MyJava directory. now when i run it with cmd line argument c: in stead of listing the file/folders in c: drive it lists the file/folders of c:\MyJava directory. in any other case its working fine.
    now if i save the file in d:\MyJava\src. again it gives same problem when CLA is d: , but working fine for any other arg.
    now xplain me why is this happening. do i have any fault or what?
    and whats the solution.
    can ne1 pls.

    to b more scecific, in the 2nd case it lists the files/folders of d:\MyJava\src folder.

  • Java does not get file list from shared folder in another server.

    Hi,
    I'm using java 1.4.2.16,
    Command below does not get file list.
    import java.io.;*..
    File file = new File("\\\\10.242.22.28\\SapMII");
    File[] files = file.listFiles();
    SapMII folder is Everyone full Control permission.
    How can i solve this problem?
    Thanks.

    Could you please post replies in a more helpful way? Just informing me that it was an NPE doesn't really tell me anything. Post the stacktrace (Exception#printStackTrace()). And the listFile() methods API has this to say:
    Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.I'm able to run this sample code easily:
    import java.io.File;
    public class TestFileList {
         public static void main(String[] args) {
              File file = new File("\\\\10.40.55.33\\shared");
              File [] files = file.listFiles();
              for(File currentFile: files )
                   System.out.println(currentFile.getName());
    }

  • Problem in finding java class file

    I am writting an application using servlets , JSP and a simple java classfile. The simple java class file is for connection pool and the name of connection pool class is DBConnectionManager . I am using JavaWebserver2.0 and I have placed this class file in .\JavaWebserver2.0\classes
    I am placing my servlets in .\JavaWebserver2.0\servlets folder. Since I am using wfm package so my servlets are placed in .\JavaWebserver2.0\servlets\wfm .
    The problem is with compiling the servlet placed in wfm folder . I get the following error:-
    TestServlet.java:11:cannot resolve symbol
    symbol: class DBConnectionManager
    location: class wfm.TestServlet
    However when I try to compile this class in servlets folder and remove the package statement from the source file, it compiles and works very fine. I am having lot of confusion as the class DBConnectionManager is in classpath but even then compiler gives error. The same class when placed in servlets folder and package statement is removed works very fine.
    Kindly help.

    Hi,
    Is the DBConnectionManager class declared public?
    Does the TestServlet import the package that contains the DBConnectionManager?
    This is all I can come up with, with the current information.
    Cheers,
    --Arnout                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Java.io.File exists() problem

    I have a web application deployed on a Windows 2000 server and am running Tomcat 4. I want to check for the existence of an image file before displaying it and am trying to use the java.io.File.exists() method. I am using the following code:
    String strPicUrl = "/images/thefile.jpg"; //Actual value comes from database
    File theFile = new File(application.getRealPath(strPicUrl));
    out.print("File Exists: " + theFile.exists() + "<br>");the actual file name in this example is "/images/theFile.jpg", and theFile.exists() always returns true if the file is there, but differs in case. If I try to display the image it doesnt show up under Tomcat because aliasing is turned off by default. I need to find a way to determine if a file exists based on actual case matching. This way if I get a "true" value, the file should be accessible and/or viewable via the JSP engine.
    Any ideas how to perform a case sensitive "exists()" regardless of the underlying OS file system?

    This looks awesome, but when I tried to implement it without creating a class, I get a method error. Here is the code below:
    String theDir = "C:\\Dir\\Subdir\\";
    FileFilter theFilter = new FileFilter() {
         private String _theFile = null;
         public boolean accept(File file)
              if (file.isDirectory()) return false;
              String fileName = file.getName();
              if (fileName.endsWith(_theFile)) return true;
              return false;
         public void setTheFile(String theFileParam)  
              _theFile = theFileParam;  
    theFilter.setTheFile("theFile.jpg");When I run this I get the following error:
    [javac] ...blah error stuff...
    [javac] cannot resolve symbol
    [javac] symbol : method setTheFile (java.lang.String)
    [javac] location: interface java.io.FileFilter
    [javac] theFilter.setTheFile("theFile.jpg");
    Since I am invoking the FileFilter object directly and not instantiating it in a class, is that causing the error or am I declaring "setTheFile()" wrong?

  • Java applet security file.list()

    I am trying to read the directory structure from a signed applet. I
    have created the applet and provided it with the
    UniversalFileAccess. I am able to read a specific file, and see all
    the contents of the file. I am wanting to performa simple
    directory listing vie the following code.
    My browser is Communictor 4.76 on Win 2000.
    blah.. blah...
    if(browser.indexOf("netscape") >= 0){
    //Assert Netscape permissions
    try{
    // tried UniversalFileRead, UniversalFileAccess,
    UniversalPropertyWrite,
    PrivilegeManager.enablePrivilege("UniversalFileRead");
    System.out.println("Netscape now has UniversalFileRead
    privilege.");
    } catch (netscape.security.ForbiddenTargetException e1) {
    System.out.println("Permission to read file system denied by
    user.");
    e1.printStackTrace();
    } catch(Throwable e){
    System.out.println("Could not enable privilege." +
    e.getMessage());
    e.printStackTrace();
    try {
    File f = new File("c:\\temp\\");
    String [] fileList = a.list();
    } catch (Throwable e) {
    System.out.println("File List failed");
    e.printStackTrace();
    I keep getting a secuity exception that I do not have priveledes to
    perform this action.
    Can anyone help!!!!!!!! I am on a deadline, and this is working just
    fine with IE.
    Please reply directly to me, as this is the first time I've ever posted
    to this newsgroup. My email is [email protected]
    Thanks,
    James Kurfees

    This question has been asked many times in these forums.
    There is no way to prevent this from a determined reverse engineer.
    Search for java obfuscators, which can help a little bit.
    The only way to prevent code stealing is to run it on your own server,
    which means not to use applets, but servlets/JSP. I am sure this is
    not what you want to hear.

  • Java code to list files in Windows O/S by FIFO sequence

    Hi,
    I am new to java and working on a project which needs to list files from Windows O/S by FIFO sequence.
    Here is the scenario,
    One of the application logs/stores files in Windows System. After that files has to be moved to another files system on AS/400 by FIFO sequence.
    I need to write java program to list files in Windows (by FIFO) and then move to different application running on AS/400.
    I am using java.io.File class and method list() and could able to list all files. But, not able to list files by FIFO sequence.
    I would appreciate to receive any thoughts implementing FIFO for listing files using java.
    Thanks,
    Siva

    Duplicate post, replied to here:
    http://forum.java.sun.com/thread.jspa?threadID=5169767&messageID=9652068#9652068

  • Problem to include java script file in servlet

    I couldn’t use any functions included in java servlet file using servlet. I made a test in jsp and it work fine but in servlet not.
    Here my code
    out.println("<jsp:include page=\"C:/path/file.js\" flush=\"true\" />");
         or          
         out.println("<script language=\"javascript\" src=\"c:/path/file.js\">");
    Although was no error but using both didn’t let me use any function inside the java script file. As I said using the same command in JSP works fine.
    How I can include the file.js correctly ?

    [email protected] wrote:
    server machineOK, imagine that I am the server and you are the client.
    I have a file "c:/documents and settings/balusc/passwords.txt".
    So now you have the path. Can you tell me the contents of the file?

  • File Making Directories Problem. java.io.FileNotFoundException

    When ever I run my program it is SUPPOSED to make the directories, instead it tells me the file doesn't exist and fails.
    Here is my Code:
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package passworddatamacsetup;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.JOptionPane;
    * @author jacobgarber
    public class Main {
         * @param args the command line arguments
        public static void main(String[] args) {
            try {
                File PasswordDATA = new File("/Applications/PasswordDATA");
                PasswordDATA.mkdirs();
                File passwords = new File("/Applications/PasswordDATA/PasswordFiles");
                passwords.mkdirs();
                File main = new File("./PasswordDATA_-_MAC.jar");
                File out = new File(PasswordDATA.getPath()+"/PasswordDATA.jar");
                copy(main, PasswordDATA);
                JOptionPane.showMessageDialog(null, "Framework setup complete!", "Completed!", JOptionPane.INFORMATION_MESSAGE);
            } catch(Exception ex) {
                JOptionPane.showMessageDialog(null, ex);
        // Copies src file to dst file.
        // If the dst file does not exist, it is created
        public static void copy(File src, File dst) throws IOException {
            try {
                InputStream in = new FileInputStream(src);
                OutputStream out = new FileOutputStream(dst);
                // Transfer bytes from in to out
                byte[] buf = new byte[1024];
                int len;
                while ((len = in.read(buf)) > 0) {
                    out.write(buf, 0, len);
                in.close();
                out.close();
            } catch (FileNotFoundException ex) {
                JOptionPane.showMessageDialog(null, ex);
    }Here is my exception:
    java.io.FileNotFoundException: /Applications/PasswordDATA

    This looks suspicious:
                File out = new File(PasswordDATA.getPath()+"/PasswordDATA.jar");
                copy(main, PasswordDATA);You probably meant:
                File out = new File(PasswordDATA.getPath()+"/PasswordDATA.jar");
                copy(main, out);

  • Problem with 'LS' command syntax for generating 'recursive' files list

    I'm having trouble getting a recursive (-R) directory listing of the contents of a flash drive --
    -- i.e., when I run the 'ls' command with the -R switch (in Terminal), I get either a recursive directory of what appears to be 'all volumes' (i.e., a very large file) or a zero-byte (empty) file.
    Terminal also keeps reporting "No such file or directory" but I don't know what it's referring to (it reports it with both the 'zero byte' listing and the 'large file' listing).
    Obviously, I'm making some 'syntax error' but I don't know what it is.
    Assuming the following . . .
    User = MK
    Flash drive = NO NAME
    . . . what is the correct command syntax to list only the contents of the flash drive (not 'all volumes')?
    My last try (it doesn't work) was:
    *ls -RTlp /Users/MK/Volumes/NO\ NAME > /Users/MK/Documents/flashdrive.dir*
    Thanks.

    Re: the original post, I should clarify that what I'm looking for is the syntax that will generate the recursive list of the flash drive's files +without first logging the flash drive+ (NO\ NAME) +as the working folder+.
    If I do the latter, I can get the recursive listing easily enough.
    What I haven't been able to do is generate the listing without first logging NO\ NAME as the working folder.
    Thanks.

  • .java.policy file problem

    Is there someone who knows how to reinitialise the java policy file at runtime?
    My signed applet writes a policy file to the users home directory, but that file is only used after closing the browser and surfing back to our page. It should immediatly use that new file.
    Someone who got some experience with that...?
    Regards

    And is it true that if you use a Thawte or verisign certificate, you will not have to change the .java.policy file?

  • Problem opening java code file

    I downloaded some code for a slide out menu and am unable to open the file after unzipping it. Yes, I am a beginner and know near to nothing about java.
    Here's the message that came up:
    Script: C:\Documents and Setting\etc...etc
    Documents\passion\ssm6_6\ssmitmes.js
    Line: 1
    Char:1
    Error: Syntax error
    Code: 800A03EA
    Source: Microsoft JScript compilation error
    So what's with that? I know it's my computer but I don't know where to go for answers so I thought here'd be a good start.
    Any hints are greatly appreciated, thanks ya'll!!

    There is some errror in The ssmitmes.js java script file. Just try to edit it and clear it.

  • OutOfMemoryError while using File.list()

    I'm facing OutOfMemoryError while using file.list(). Below is the description of the requirement
    We have a directory structure of the following format -
    **sourcedir\<date folders>\No Retry\<reason folders>\..\..\....\<*.ini files>**
    sourcedir will be passed as argument to the program. The directories present in between "<>" can be in multiples of 10. The *.ini files can be in multiple of lacs in each directory.
    The program is required to browse through the directory structure and look for *.ini files. The *.ini files are parsed for some data which needs to be stored in data base. We are using "File.list()" to load the name of files and FileFilter to find *.ini" files. As the number of files are huge the program is throwing OutOfMemoryError. We have increased heap space, it solved the problem. But we are looking for a solution which will not throw this error in future as the number of files may increase.
    Can you please suggest us a technique to solve this permanently as we are beginners to java.

    I suggest you try using a memory profiler to see where your memory is being used.
    The problem you suggest shouldn't consume so much memory.

  • FTP Get File List Action Block, It's double listing files!  ver 11.5

    Hi guys.. I have a good one!   I have an FTP Get File List action block in my BLS transaction.  Occasionally, it double lists the files in its output.   For testing I put a repeater with a logevent output where I log the filename, date, and size.  Heres what I saw for my action block output.
    2009-02-13 00:38:00,963  [UserEvent] : File Name: DMM_Export_0010056.txt, File Date 2009-02-13T00:36:00, File Size 339
    2009-02-13 00:38:00,963  [UserEvent] : File Name: DMM_Export_0010056.txt, File Date 2009-02-13T00:36:00, File Size 339
    This is xMII  version 11.5.6 b73  with java 1.4.2_07
    I have a workaround by putting in a distinct action block, after the filelist, but anybody have an idea why this might happen?   My theory is that something might be occuring if the file is being written to while we try to process it, but not sure. 
    I've been building BLS parsers since 2003, (Remember those fun times with Jeremy?)   I've never seen this happen.

    My example is a sample log file before the distinct action.  The general log shows nothing other than the subsequent transaction errors I get as a result of running the same error twice (Tcode return from BAPI calls etc)
    Here is something else interesting..  my userlog file is acting funny, like its trying to write on top of itself.  could it be the transaction is actually running twice or parts of it? 
    For example look at the following log entries
    This is how my log file entry for a production confirmation should look
    2009-02-13 00:38:06,854 [LHScheduler-Int10_NestingWOProdConf] INFO   UserLog - [UserEvent] :
    However sometimes... its looking like this...
    2009-02-13 2009-02-13 00:38:11,854 [LHScheduler-Int10_NestingWOProdConf] INFO   UserLog - [UserEvent] :
    Like it started writing to the log, then started again.
    The problem we are having is that we have JCO calls to SAP in this transaction that does goods movement, we get locking / block errors back from our  saying that we (our sap account) is already updating the information.   Sometimes the information would be posted twice!  You can see how this has become a HUGE issue posting data to a LIVE system twice.
    This is happening on 2 xMII servers.

Maybe you are looking for