How to read files in whole directory

hi everybosy i have got a directory called grepdatabase in the following path
/users/zer/gd.
it has 3000 files in it.i have to read each file and do soem process and write it into another file.
but with the following code it says, directorydoesnot exists.but i have the directory,with all the files in it.
File database = new File("c:/Domain/nbi.bbsrc.ac.uk/Users/zer/gd");
        if (database.exists() && database.isDirectory()) {
            String datafiles[] = database.list();
            for (int i = 0; i < datafiles.length; i++) {
                System.out.println("processing file: " + database.getAbsolutePath() +
                        "/" + datafiles[0]);
        } else {
            System.out.println("Database exists: "+database.exists()+"\nDatabase is Directory: "+database.isDirectory());
        }can anyone help me how to read multiple files...

ur code can be little modified as follows to make it work flawlessly
       File database = new File("c:/Domain/nbi.bbsrc.ac.uk/Users/zer/gd");
              if (database.exists() && database.isDirectory()) {
                  //String datafiles[] = database.list();
                  //Instead use file list here
                  File[] datafiles = database.listFiles();
                  for (int i = 0; i < datafiles.length; i++) {
                  //    System.out.println("processing file: " + database.getAbsolutePath() +
                  //            "/" + datafiles[0]);
                   System.out.println("processing file: " + datafiles.getName());
} else {
System.out.println("Database exists: "+database.exists()+"\nDatabase is Directory: "+database.isDirectory());
BR

Similar Messages

  • How to read files from current directory for applet

    I have an applet that needs to read some audio files located in its current directory on the server and I just can't seem to figure it out...maybe I am being dumb...any help?

    You can use the ListSorter File Adapter Configuration property to sort based on timestamp. Basically add the following property to the inbound JCA file:
    <property name="ListSorter"
    value="oracle.tip.adapter.file.inbound.listing.TimestampSorterAscending"/>
    <property name="SingleThreadModel" value="true"/>
    More info see section 4.2.6 in http://docs.oracle.com/cd/E23943_01/integration.1111/e10231/adptr_file.htm

  • How can I copy the whole directory of files from PC to iPad?

    How can I copy the whole directory of files from PC to iPad ?

    Get an app that reads PDF's, such as iBooks or GoodReader or Readdle Docs, then use the file transfer part of iTUnes to get those files to your iPad, through iTunes. ( I have no experience with goodreader, but with ReaddleDocs you can move the files, then create folders to put them in to keep them organized)

  • [Urgent] How to read files from different directories?

    I am new to Java Programming, I would like to know how to read files from directories other than the current one? (example as follows)
    ProjectDirectory
    |--MainDirectory
    |--MainProgram.java
    |--SupplementDirectory
    |--SupplementProgram.java
    |--Pictures
    |--Image.gif
    What should I write in the MainProgram.java so that I can use the supplementProgram.java from MainProgram and read the Image.gif file from the MainProgram.java?
    Thanks

    Run through the I/O tutorial here. It should get you up to speed on this sort of thing...

  • PI sender communication channel not reading files from NFS directory

    Hello,
    I have a sender communication channel configured to read file from NFS directory which is on ECC server. A program in ECC generates the file and puts it on the ECC server in the output directory. PI sender communication channel is supposed to pickup this file and process it. If I give the NFS path as the source directory, I am getting error: Configured source directory '//Server/DIR/OUT' does not exist. I tried putting '
    Server\DIR\OUT' too but same error. Do I have to add the NFS path of ECC into PI as logical path?
    Any suggestions?
    Thanks,
    Sangita

    Hello Sangita,
    Your ECC server is an external system, therefore you need to activate FTP service in that system and use the transport protocol FTP:
    http://help.sap.com/saphelp_nw04/helpdata/en/e3/94007075cae04f930cc4c034e411e1/content.htm
    You can use NFS protocol when you have a local directory in XI server.
    Best Regards,
    .Luis Bernal.

  • Reading file from oracle directory at client side

    Hi,
    I have a SWING app. which connects to an Oracle db.
    My goal is to read files from oracle directory with java through JDBC. I export some dumps with datapump and they need to be transferred to a client machine. There is no access to oracle directory at network filesystem level.
    Please advice!
    TIA, Sandor

    An Oracle Directory has an underlying OS directory associated with it, Oracle just overlays it's control structure onto an existing folder in the OS. You can manipulate the files with stored procedures in Oracle or at the OS level from outside of Oracle.
    If you manipulate the files from the OS level, outside of Oracle, you may need a refresh of the Oracle Directory structure.

  • How to read files in java

    Hi
    I have a directory that has files put into it. What I want to do is open/read these files in java and then do something to it and then move the file to another folder called passed or failed.
    What I dont know is how can I read a file who's name i dont know of?
    Example I know the directory the files will go into
    c:\test\csv\
    but the file name i dont know of they could be called anything and have any extension!
    My program will loop every 10 minutes and check if there are files in the directory. If so it will process them. Once files have been processed their should be no more files left in this directory.
    Kind Regards
    Antek

    Hi
    Thanks for your answer it pointed me in the right direction. I now have small problem. If i do directory list like the code below it gives me all the files but it also gives me any directories in the folder. How can i tell it to give me files only and no folders.
    Many thanks
    import java.io.*;
    import java.util.*;
    public class SimpleDirList
         public static void main(String [] args) {
              String directoryName;
    File directory ;
    String[] files;
              directory = new File("c:\\java_code");
              if (directory.isDirectory() == false) {
                   if (directory.exists() == false) {
                        System.out.println("There is no such directory!");
                   } else {
                        System.out.println("That file is not a directory.");
              } else {
                   files = directory.list();
                   System.out.println("Files in directory \"" + directory + "\":");
                   for (int i = 0; i < files.length; i++) {
                        //do something
                        System.out.println(" " + files);

  • How to pick files from ECC directory

    Hi All,
    I have to pick files from the directory of ECC. can anyone tell me how to configure the sender File apapter? Can i use NFS for the same?
    Regards,
    Lavanya R

    Hi Lavanya,
    With my knowledge two ways to pick the file from ECC using File adapter.
    1. If you use NFS, mount point should be created in ECC for the Directory to access from PI.
    2. If you use FTP, FTP ports must be opened between PI and ECC.

  • HOW to read file using ftp???

    Hi to all,
    I have problem with reading file using ftp connection, i want to read only 1024 bytes for one time, and i have
    next code wich read this:
    byte buffer[] = new byte[1024];
    while( (readCount = input.read(buffer)) > 0) {
    bos.write(buffer, 0, readCount);
    but I dont know how to put all read data in one byte[] if i dont know length of file.
    I can't do some like: byte file[] = new file[1000000];
    Thanks for all sugestions!

          * Download a file from a FTP server. A FTP URL is generated with the following syntax:
         * <code>ftp://user:password@host:port/filePath;type=i</code>.
          * @param ftpServer FTP server address (incl. optional port ':portNumber').
          * @param user Optional user name to login.
          * @param pwd Optional password for <i>user</i>.
          * @param fileName Name of file to download (with optional preceeding relative path, e.g. one/two/three.txt).
          * @param destination Destination file to save.
         * @throws MalformedURLException, IOException on error.
         public void download(String ftpServer, String user, String pwd, String fileName, File destination) throws MalformedURLException, IOException {
            if (ftpServer != null && fileName != null && destination != null) {
                StringBuffer sb = new StringBuffer("ftp://");
                if (user != null && pwd != null) { //need authentication?
                    sb.append(user);
                    sb.append(':');
                    sb.append(pwd);
                    sb.append('@');
                }//else: anonymous access
                sb.append(ftpServer);
                sb.append('/');
                sb.append(fileName);
                sb.append(";type=i"); //a=ASCII mode, i=image (binary) mode, d= file directory listing
                BufferedInputStream bis = null;
                BufferedOutputStream bos = null;
                try {
                    URL url = new URL(sb.toString());
                    URLConnection urlc = url.openConnection();
                    bis = new BufferedInputStream(urlc.getInputStream());
                    bos = new BufferedOutputStream(new FileOutputStream(destination.getName()));
                    int i;
                    while ((i = bis.read()) != -1) { //read next byte until end of stream
                        bos.write(i);
                    }//next byte
                } finally {
                    if (bis != null) try { bis.close(); } catch (IOException ioe) { /* ignore*/ }
                    if (bos != null) try { bos.close(); } catch (IOException ioe) { /* ignore*/ }
            }//else: input unavailable
        }//download()If you don't want to strore the data into a file, use ByteArrayOutputStream instead of a FileOutputStream.

  • How to read file on demand (or) avoid polling in bpel 11g?

    Hello -
    Scenario - Receive two files(A & B) which should end up in two tables (Header, Lines)
    BPEL process -
    1) Receive acitivity - To Read file (A) via File adapter
    2) Tranformed
    3) Invoked the Db adapter to insert into "Header" table
    4) Added another Receive activity - To Read file (B) via File adapter
    5) Transformed
    6) Invoked the Db adapter to insert into "Line" table
    Issue - Step 4 gets fired as a SEPARATE instance (but no data in lines table) . At the end - I see the BPEL process which is waiting for File B. Even after I dropped File B - I dont see any records going into tables.
    Is there a better way to design this process? Do I need to separate BPEL process to insert into Header & Line table? If so - how can I make this sequential process?
    Appreciate detailed steps, if possible
    Thanks
    Babu

    If its really a SyncRead Step 4 willl not run as a seperate process.
    Step1: Initiates the process once the header file arrived
    Step4: Will be invoked like a normal partnerlink.
    Just make sure, you put the lines file before the header file in the directory.
    If it doesnot resolve the problem, send your project to me helloprasanna at rediffmail.com . I'll have a look.
    --Prasanna                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to read file from remote machine

    Hello,
    Hi, i would like to know how to read text file from remote machine using java source code, any code ?
    Thanks very much;
    Best regards
    Kim

    On the server, perform the following steps:
    Parse the request and determine the file to serve
    Open a FileInputStream to the appropriate file
    Obtain a reference to the Servlet OutputStream
    Pipe the bytes from the file to the output stream
    Flush and close the streamYou might want to call HttpServletResponse.setContentType("application/octet") to indicate to the browser that a file download will be occurring. Do so before getting the reference to the Servlet's OutputStream.
    - Saish

  • How to store file into a directory?

    i want to save the file(text file) into the directory which i have created using File object in the codes below. how do i do it?
    public void saveString(String filename, String string)
              //declare textfile to be null
              PrintWriter textFile = null;
              String line = null;
              try {
                   // writes to write.txt
                   textFile = new PrintWriter (new FileWriter(filename,true));
                   line = string;
                   // save string in textfile
                   textFile.println(line);
                   textFile.close();
                   // create a directory (to store (output).xml file)
              File fobj = new File("Testing");
              fobj.mkdir();
              catch (IOException e) {
                   System.out.println("Error in opening file");
                   System.exit(0);
         }

    create the directory first and then create the file u want liek this
    File f = new File (fobj,filename);
    and then open the fiel to write like this
    textFile = new PrintWriter (new FileWriter(f,true));
    regards
    rohan

  • How to read file from server if I have a logical file path?

    Hi guys,
    I'm having a pretty "on the run" question,
    My program is currently reading a file from server using "open dataset" with file path like this (just example)
    /usr/interface/abc/bcd/testfile.dat
    Now I got a requirement to make it more consistent to read files, instead of reading that physical file name, I should read the files from a specific folder using logical path.
    So I go to T code "FILE" and created a logical path called ZABC_FILE_PATH, unix compatible, with physical path is (for example),
    /usr/interface/<sysid>/<client>/<filename>
    My question is, can I still use open dataset statement to read this? if yes, how do I do that? If no, there should be alternative way, please let me know what you think. Thanks,

    Thanks all, I figured it out.
    ONe thing is that typo double quote
    The other thing is the importing part, I need the full file path.
    CALL FUNCTION 'FILE_GET_NAME_USING_PATH'
      EXPORTING
        CLIENT                           = SY-MANDT
        logical_path                     = 'ZABC_MY_LOGICAL_FILE_PATH'
    *   OPERATING_SYSTEM                 = SY-OPSYS
    *   PARAMETER_1                      = ' '
    *   PARAMETER_2                      = ' '
    *   PARAMETER_3                      = ' '
    *   USE_BUFFER                       = ' '
        file_name                        =  v_1
    *   USE_PRESENTATION_SERVER          = ' '
    *   ELEMINATE_BLANKS                 = 'X'
      IMPORTING
        FILE_NAME_WITH_PATH              = v_what_I_need
    * EXCEPTIONS
    *   PATH_NOT_FOUND                   = 1
    *   MISSING_PARAMETER                = 2
    *   OPERATING_SYSTEM_NOT_FOUND       = 3
    *   FILE_SYSTEM_NOT_FOUND            = 4
    *   OTHERS                           = 5
    I really appreciate your contributions, thanks again!

  • How to read file from server

    Hi,
    When i try to read file from server,the following message is displayed .
    ORA-29532: Java call terminated by uncaught Java exception: java.security.AccessControlException: the Permission (java.io.FilePermission /tmp read) has not been granted to EWMTRACKTEST. The PL/SQL to grant this is dbms_java.grant_permission( 'EWMTRACKTEST', 'SYS:java.io.FilePermission', ' /tmp', 'read' )
    ORA-06512: at "EWMTRACKTEST.GET_DIRLIST_EWM", line 1
    ORA-06512: at line 1
    thanks and regards
    P Prakash

    it seems obvious, user EWMTRACKTEST doesn`t have access to directory /tmp and the file under that.
    try to give read permission and try again.
    you could use command line like 'chmod' to grant permissions.

  • How to read file header/open filein binary mode

    i am using FileConnenction API to read from a file. how can i open a file in binary mode so that i can read file header. In other words i want to open a file in binary mode.

    You can always try looking at the [Header Signatures|http://www.techpathways.com/uploads/headersig.txt]. But it would probably be easier to adjust your application so it doesn't have to guess.
    ~

Maybe you are looking for

  • Error Message when importing

    I am trying to import a CD into my library and it say " Error occurred while converting the file. you do not have enough access privileges for this operation. iTunes could not save your iTunes Music folder because you do not have write access. check

  • Windows Server 2008 R2 Logical Disk monitor is not listed in SCOM 2012

    Dear Experts, I tried to create an override of Logical Disk space threshold value changes on one of Windows 2008 R2 OS, But unable to find the respective monitor of 'Windows Server 2008 R2 Logical Disk' monitor in the scope, But I can see Windows Ser

  • Transfer PC to Mac Where did it go?

    I transfered Outlook and contents to the mac with Migration assistant it says it was sucsesful but dont have any idea where everything went. My Address book is still empty. Help! 

  • Getting an error when trying to shut down R12 application.

    when trying to shut down R12 application getting the below mentioned error. adstpall.sh: Database connection could not be established. Either the database is down or the APPS credentials supplied are wrong. As per previous thread checked the database

  • Write access blocked on additional drives

    I recently had an issue with my Mac Pro with Leopard where it was stuck in boot loop. I followed the fix of using the disk utility off the Leopard disk to repair permissions and everything seemed to be fixed. Then, for no reason I can think of, after