List files in directory?

Hey there. I'm brand new to this JSP stuff. I'm developing a solution whereby a customer logs into a page, the page looks into a directory for invoices associated with that customer (this will be accomplished through naming conventions) and then gives the customer a dropdown with their invoices in it. I wanted to start with the simplest part of the code and work forward with the conditions etc. So what I want to do first is just get the page to list all the files in the invoices directory. Can anyone help me with that?
Thanks!

Q&D, should list the current directory contents.
I want to do first is just get the page to list all
the files in the invoices directory. Can anyone helpimport javax.swing.*;
import java.util.*;
import java.io.*;
import java.io.OutputStream.*;
import java.io.InputStream.*;
import java.util.zip.*;
import java.text.*;
import java.awt.*;
import java.awt.event.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.Date;
import javax.swing.table.*;
import java.net.URL;
import java.sql.*;
import java.net.*;
public class Servlet extends HttpServlet {
public final static String IPAddress = "127.0.0.1";
public final static String IPAddressKey = "ipaddress";
public Servlet()
public void init(ServletConfig conf) throws ServletException {
     super.init(conf);
public void doPost (HttpServletRequest req, HttpServletResponse res)
     throws ServletException, IOException {
     HttpSession session = req.getSession( true );
     String sessionID = session.getId();
     session.putValue( "sessionID", sessionID );
     session.putValue( IPAddressKey, IPAddress );
     ServletContext sc = null;
     RequestDispatcher rd = null;
     String url = "/Dir.jsp";
     sc = getServletContext();
     rd = sc.getRequestDispatcher( url );
     System.out.println( "S url forward " + url );
     rd.forward( req, res );
<html>
<%@ page session="false" language="java" import="java.io.*" %>
<body bgcolor="white">
<font size=4>
<%
     try {
     File f = new File( "." );
     File[] fs = f.listFiles();
     for( int i = 0, ii = fs.length; i < ii; i++ )
          %>
<%= fs[ i ] %><br>
<%
     } catch (Exception e) {
     System.err.println(e);
%>
</font>
</body>
</html>

Similar Messages

  • List file under directory using JSP

    Hi,
    Does anyone have a code to list all files under a certain directory in JSP? Thanks alot!

    thank you so much... l already have a code working, but l can't make it download excle file as it displays them online. l want to force download. thanks
    <%@ page import="java.io.*" %>
    <%@ page import="java.util.*" %>
    <%@ page errorPage="listFiles_error.jsp" %>
    <%
    // To change the directory that is listed, change this variable
    // \ character must be escaped with a second \ as below
    String directoryName = "c:\\Tomcat\\webapps\\examples\\jsp";
    // This variable needs to point to the URL that will be after the
    // domain name for the above directory (needs to be setup in your
    // application server)
    String urlName = "/examples/jsp/";
    // Loads the list of files in the directory
    File directory = new File(directoryName);
    File[] fileList = directory.listFiles();
    Hashtable sortedFiles = new Hashtable(fileList.length);
    // Loops through each file
    for(int i=0; i<fileList.length; i++) {
    File file = fileList;
    // Skip subdirectories
    if(file.isDirectory())
    continue;
    String name = file.getName();
    int dotIndex = name.indexOf('.');
    // Skip files with no extension
    if(dotIndex < 0 || dotIndex+1 >= name.length())
    continue;
    String fileName = name.substring(0,dotIndex);
    String fileType = name.substring(dotIndex+1).toLowerCase();
    // Only process PDF, REP, and XLS file types
    if(!fileType.equals("pdf") && !fileType.equals("rep") && !fileType.equals("xls"))
    continue;
    // Organize like filenames for processing later
    Hashtable fileTypes = (Hashtable)sortedFiles.get(fileName);
    if(fileTypes == null) {
    fileTypes = new Hashtable(10);
    sortedFiles.put(fileName,fileTypes);
    fileTypes.put(fileType,file);
    %>
    <html>
    <head>
    <title>
    listFiles
    </title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
    <!--
    body {
         background-image: url(bkg2.gif);
         margin-left: 0px;
         margin-top: 0px;
         margin-right: 0px;
         margin-bottom: 0px;
    .style2 {font-size: large; color: #000066; }
    .style3 {font-size: medium; color: #000066; }
    -->
    </style></head>
    <body bgcolor="#ffffff">
    <table width="100%" border="0">
    <tr>
    <th background="chead.gif" scope="col"><div align="left"><img src="jpmorgan_logo.gif" width="200" height="40" border="0"></div></th>
    </tr>
    </table>
    <p> </p>
    <TABLE width="700" height="106" border="1" align="center" cellpadding="1" cellspacing="1" bordercolor="#000033">
    <tr>
    <th width="370" height="33"><div align="left" class="style2">Name</div></th>
    <th width="40"><div align="left" class="style2">PDF</div></th>
    <th width="40"><div align="left" class="style2">Rep</div></th>
    <th width="40"><div align="left" class="style2">Excel</div></th>
    </tr>
    <%
    // Loop through each file name, outputting the data in a tabular format.
    Enumeration e = sortedFiles.keys();
    while(e.hasMoreElements()) {
    String fileName = (String)e.nextElement();
    Hashtable fileTypes = (Hashtable)sortedFiles.get(fileName);
    File pdfFile = (File)fileTypes.get("pdf");
    File reportFile = (File)fileTypes.get("rep");
    File excelFile = (File)fileTypes.get("xls");
    %>
    <tr>
    <td height="63" align="left" valign="bottom"><div align="left" class="style3"><%=fileName%></DIV></td>
    <% if(pdfFile != null) {
    // Output the PDF Entry
    %> <td width="40" align="left" valign="bottom"><a href="<%=urlName+pdfFile.getName()%>"><img src="PDF.gif" width="40" height="40" border="0"></a></td>
    <% } else {
    %> <td width="40" align="left" valign="bottom"> </td>
    <% }
    %>
    <% if(reportFile != null) {
    // Output the Report Entry
    %> <td width="40" align="left" valign="bottom"><a href="<%=urlName+reportFile.getName()%>"><img src="Rep.gif" width="40" height="40" border="0"></a></td>
    <% } else {
    %> <td width="1" align="left" valign="bottom"> </td>
    <% }
    %>
    <% if(excelFile != null) {
    // Output the Excel Entry
    %> <td width="40" align="left" valign="bottom"><a href="<%=urlName+excelFile.getName()%>"><img src="xls.Gif" width="40" height="40" border="0"></a></td>
    <% } else {
    %> <td width="1"> </td>
    <% }
    %>
    </tr>
    <%
    %>
    </table>
    </body>
    </html>

  • Listing files of directory on application server

    hi all,
    I want to download a list of files from the application server.
    I tried the functions:
    - SUBST_GET_FILE_LIST
    - EPS_GET_DIRECTORY_LISTING
    - RZL_READ_DIR_LOCAL
    but the result gives me the name of my file truncated.
    My filename is much longer than the functions give me.
    Is there any other function, or can i bypass this problem in a way.
    Thanks in advance.
    Merijn.

    Hello,
    This is a common problem with this FMs. Even SAP acknowledges this:
    In EPS_GET_DIRECTORY_LISTING you have this:
    data: begin of file,
            dirname(75) type c, " name of directory. (possibly truncated.)
            name(75)    type c, " name of entry. (possibly truncated.)
          end of file.
    The FM uses a Kernel Call 'C_DIR_READ_NEXT' to get the list of the files in the directory. The file name is returned in the field file-name.
    call 'C_DIR_READ_NEXT'
              id 'TYPE'   field file-type
              id 'NAME'   field file-name
              id 'LEN'    field file-len
              id 'OWNER'  field file-owner
              id 'MTIME'  field file-mtime
              id 'MODE'   field file-mode
              id 'ERRNO'  field file-errno
              id 'ERRMSG' field file-errmsg.
    The program RSWATCH0(trxn: AL11) also uses the Kernel call but the structure file is different.
    DIrectory name can be 1024 character long & file name is 260 character long
    data: begin of file,
            dirname(1024)    type c,  " name of directory. (possibly
                                           " truncated.)
            name(260)        type c, " name of entry. (possibly
                                           " truncated.)
            type(10)    type c,            " type of entry.
            len(8)      type p,            " length in bytes.
            owner(8)    type c,            " owner of the entry.
            mtime(6)    type p, " last modification date, seconds since 1970
            mode(9)     type c, " like "rwx-r-x--x": protection mode.
            useable(1)  type c,
            subrc(4)    type c,
            errno(3)    type c,
            errmsg(40)  type c,
            mod_date    type d,
            mod_time(8) type c,            " hh:mm:ss
            seen(1)     type c,
            changed(1)  type c,
          end of file.
    So one workaorund would be to copy EPS_GET_DIRECTORY_LISTING to some custom FM & change the length of the structure file to suit your requirement
    BR,
    Suhas
    PS: Use of Kernel Call is for internal use only & is highly not recommended by SAP.

  • How to list files from directory in list box?

    Hi all,
    Here is what I want to implement: I have several pattern files that'd
    be sent to special motor controller. What I want is: display these
    files in the list box on the interface, so that user can click on the
    file he wants, then run the program, and this file will be the input
    to my controller.
    Thank you!

    lv 6.1 attached.
    cheers,
    ~j5
    2006 Ultimate LabVIEW G-eek.
    Attachments:
    Get_File_Names.vi ‏54 KB

  • Failing to list files in remote directory using FTP

    Since I've been using a proxy with FTP transport for pull files from a remote server during several months. Now it started to work just sometimes
    ####<Apr 11, 2011 1:33:50 PM BRT> <Error> <WliSbTransports> <WN7-6J6VJN1> <AdminServer> <pool-9-thread-1> <weblogic> <> <f2be7f1e2af484b9:-47b5d228:12f456185e7:-7ff1-000000000000002c> <1302539630973> <BEA-381602> <Error encountered while polling the resource for the service endpoint ProxyService$Infolease$1_0$ProxyServices$Contract$SendBookingConfirmationPS: com.bea.wli.sb.transports.TransportException: <user:davi_diogo>Unable to list files for directory:.
    com.bea.wli.sb.transports.TransportException: <user:davi_diogo>Unable to list files for directory:.
         at com.bea.wli.sb.transports.ftp.connector.FTPWorkPartitioningAgent.execute(FTPWorkPartitioningAgent.java:218)
         at com.bea.wli.sb.transports.poller.TransportTimerListener.run(TransportTimerListener.java:75)
         at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
         at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
         at java.util.concurrent.FutureTask.run(FutureTask.java:139)
         at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)
         at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:207)
         at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:909)
         at java.lang.Thread.run(Thread.java:619)
    I configured the service account with my own username, and I do make sure that I have the rights over my home\user directory. (I tested with WINSCP and putty).
    I haven't done any modification to make this start happening.
    following my proxy configuration:
    protocol: ftp
    URI: ftp://myhost/
    mask: *.XML
    but no success.
    I said "sometimes" above because it works after ~15 tentatives. Perhaps this could be a issue in my remote server OS.
    Has anyone faced this issue before?
    Thanks in advance,
    Davinod

    Please refer -
    Error encountered while polling the resource for the service endpoint
    Regards,
    Anuj

  • Searching file from directory located at http path.

    Hi All,
    I have made the program to search for a file in a directory and its subdirectories. This is working fine when my directory is located on local machine. But if the same directory is placed in HTTP path, the code fails to search a directory. Does anyone has idea how can i connect to site so as to access the directories. I used URL and URLConnection to read and write file to the site, and this is also working fine but when it comes to directories i find no solution. Please help.

    This works fine if i map http://flash/ on my C: and
    try to list files in directory C:\Mojo. Can you please
    tell how can i know whether the http server i am
    trying to access allows directory listing or not.
    Because if it does not i have administrator rights on
    the server and i can make the changes required.You can see if your Web server allows directory listing by simply
    typing in the URL you want to examine, inside your browser, and see if
    it shows you a directory listing. For instance, if you type in:
    http://flash/Mojo/
    in your browser's address bar, and you see a list of files in that
    directory, then your Web server supports directory listing.
    Note, though, that you can't use the File list() method to get a list of files.
    You'll have to make a connection, read the input stream, and then parse
    the filenames out of the HTML that the Web server returns. (You can see
    what the HTML looks like, by doing View Source inside your brower. That's
    what you'll get back from your Java program.)
    --Steve

  • Get file list in a directory

    Hi,
    How can i get the files liste in a directory from forms ? I want to know all the files in c:\my_dir\
    Thanx
    Herome

    Thanks but my form must run on different environement and dir will not return the same output to my_file.txt ! Is there any other "cleaner" way to do the job ?
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Dino ([email protected]):
    U can use Host command. I.e.
    Host ('dir c:\my_dir > my_file.txt');
    and then u can read this ascii file.
    Hope this helps.
    Bye Dino<HR></BLOCKQUOTE>
    null

  • List files stored in a Directory Object

    Hi,
    I looked on Google, on Oracle DB docs and here to find a convenient way to list files stored in a DIRECTORY for batch loading in a table with PL/SQL. But no luck, UTL_FILE doesn't seem to have a method for directory listing. I saw examples with some workaround like putting files list in a text file prior to loading. The directory is feeded by other process and network services, so I don't know the filelist that I need to import and, then delete. I dont have access to the server console and it's impossible for me to dump a kind of «dir» result into a text file. I saw other examples using Java, but it looks like I don't have access to Server Side Java too.
    Is there a simple way to do that in PL/SQL only?
    If not, I'll ask to the DBA the necessary rights to compile/run java on the server side...
    The DB target versions for this requirement are 10g and 11g (mainly) on Windows environment.
    Thanks
    Bruno

    brlav35 wrote:
    The XUTL_FINDFILES seems to be the more convenient way. If that works for you, I certainly have no objection. In a lot of environments, though, that package would be problematic.
    1) It must be installed in the SYS schema. That's generally frowned upon and lots of sites would never allow user code to go into the SYS schema. Chris is a bright guy, so I'm sure the risk of it causing harm is minimal (most likely during an install or upgrade), and it will almost certainly never cause you harm, but that would be a political show-stopper at a lot of places.
    2) The package body is wrapped (if there is a version with the package body in clear text, this point is moot). Again, Chris is a well-respected guy, so I have every confidence that the code is not malicious, but asking a DBA to install a wrapped package you downloaded from the internet into the SYS schema on a production database should generate a crud-load of red flags. This is almost certainly just a theoretical danger, but DBAs and audit compliance regulations care a great deal about theoretical dangers. If someone hacked the web site and uploaded their own wrapped bit of code that had a back door, for example, it would be very hard to catch.
    3) Under the covers, the package is querying one of the undocumented X$ views. Oracle is free to change those views over time, which would potentially cause the package to stop working or stop working correctly in some way. If you're developing code for a system that may be around for a number of years, that becomes a concern. It's unlikely that Oracle will change the particular X$ view that is being referenced here over the lifetime of your code base, but it's more than a trivial concern.
    4) The package is determining what directories a user has access to, that's not Oracle enforcing the restriction. Probably not too big a deal, but it is probably safer from a regulatory compliance standpoint to be able to rely on Oracle the database enforcing privileges rather than relying on a delivered package to enforce those privileges. It's the difference between telling Oracle via specific grants which directories the JVM can access vs. writing your own wrapper that enforces those restrictions. In the end, the restrictions are enforced, but in one case you're relying on the developers of the Oracle database and in the other you're relying on external developers.
    Just to re-iterate-- Chris is a brilliant guy, I don't mean this in any way to impugn him or his code. I am totally confident that his code works, that it works well, and that it will continue to work going forward. My concerns are purely on the political/ regulatory side of things, not on the technical side of things. Technically, I am confident that the code is top-notch.
    Justin
    Edited by: Justin Cave on Sep 9, 2009 12:38 PM
    I wrote this before seeing the last few bits of the exchange where you and Chris already talked about the first point.

  • List of Files in directory on AS

    WEBUTIL.DIRECTORY_LIST gives me the list of files on the client. But I need List of Files in directory on App Server . My App server is on LINUX and client is Windows. So How can get through oracle forms a List of Files in directory on Application Server .
    I will appreciate help ?

    I don't know if it helps you(if not excuse me)
    look at
    List of Files in directory on AS
    Running HOST Commands
    If you have a host command of the form:
    HOST ('DEL c:\temp.txt')
    This will work in both client/server and Web deployed environments, but in web
    deployed environments the command runs on the middle tier.
    in Linux ls -la > .....

  • "no such file or directory"--but file's listed with ls -al

    How do you delete a file which is listed with "ls -al" in Terminal,
    but when you try to 'sudo rm' it, you get "no such file or directory"?
    The file in question is a troublesome temporary Excel spreadsheet file--something like "~$TroublesomeFile.xlsx". 
    When I run "ls -al", it's listed with the flags "-rw-r--r--@".
    Thanks much for your time!
    riprap

    If the file really starts with ~ then this is a "Magic" character to the shell.  It says to look for your home directory.
    If the file really has a $ in it, then this is a "Magic" character to the shell.  It tells the shell to substitute the contents of variable TroublesomeFile in the command line.  If the variable does not exist, then nothing is substituted for the variable name.
    If you really have all these "Magic" characters in the file name, then protect it by using single quotes around the file name:
    rm '~$TroublesomeFile.xlsx'
    If that doesn't work, then please show the exact command used to try the 'rm'
    AND please show the exact error message.  Do not summarize.

  • Returning list of files in directory not working.

    Gidday
    I'm using the following code to try to put a listing of files in a dir into an array.
    I created a dir call myDir in the same place as my .swf and .air, and placed a file in it.  But I get error messages telling me the File or directory does not exist.
    Why would this be?
    var dir:File = File.desktopDirectory.resolvePath("myDir");
    var files:Array = dir.getDirectoryListing();
    Thanks for taking a look.

    OK (still trying to get my head around the folder structure)
    Say my project exe is called test.exe, and  I also have a folder called image_files and another called text_files - how do I access the image_files folder, and how do I write txt documents to the text_files folder?  In other words, I don't want to access the user's folder, or the application storage folder, just specific folders that I have set up in my Flash as3 project.
    Or does security prevent accessing and writing to such folders?
    So how would I alter the following code to write to the text_files folder?
    function saveHandler(event:Event):void {
    var file:File = File.applicationStorageDirectory.resolvePath( "myjot.txt" );
    var jot:String = taEditor.text;
    var stream:FileStream = new FileStream();
    stream.open( file, FileMode.WRITE );
    stream.writeMultiByte( jot, File.systemCharset );
    stream.close();
    I want the user to be able to copy image and video files to the image_files folder, and then I have access to these in the air app.  So I don't want to put them in the application Storage Directory because A) like you said, it's not designed for large amounts of data, and B) I don't want the user to have to navigate to the app data folder - I want to keep navigation simple - so program files/my app/image_files (or preferably give them the option of choosing the folder where they copy their image and video files to - so it could be on d) drive for example).
    Thanks for your time and help
    Shaun

  • Listing files of a directory

    I have a block non single record and each record must receive the file name of a directory.
    Does anybody know how can i list files of a directory? Is there any object or package i've got to use?
    Thanks for attemption.

    Is the directory a single directory that your db server has access to? if so you can use a bit of java (in the db), pl/sql and sql to list the files in the given directory in a temporary table, then you can query that table to show in your form.
    Should be able to google a solution by searching on "oracle dirlist" or let me know and I can post what I used here.
    --pat
    PS. how does one get code snipits to format nice when posting here?

  • Delete file from directory which

    Hi ,
    I want to delete files from a directory in  Application server.
    I have the file name as fn_13/07/2007.txt
    Have a condition that files should be deleted which are less  than 10 days.
    Is there any function module to do this.
    Thanks in Advance.
    Regards,
    Indhra

    Hello Indhra,
    These methods may help ( from CL_GUI_FRONTEND_SERVICES )
    <b>DIRECTORY_BROWSE</b>     Static Method     Public          Shows a Directory Selection Window
    <b>DIRECTORY_CREATE</b>     Static Method     Public          Creates a Directory in the Client
    <b>DIRECTORY_DELETE</b>     Static Method     Public          Deletes a Directory in the Client
    <b>DIRECTORY_EXIST</b>     Static Method     Public          Checks if a directory exists
    <b>DIRECTORY_GET_CURRENT</b>     Static Method     Public          Returns the Current Directory
    <b>DIRECTORY_LIST_FILES</b>     Static Method     Public          Lists Files in a Given Directory
    <b>DIRECTORY_SET_CURRENT</b>     Static Method     Public          Sets the Current Directory (Do NOT Use)
    <b>ENVIRONMENT_GET_VARIABLE</b>     Static Method     Public          Gets an Environment Variable
    <b>ENVIRONMENT_SET_VARIABLE</b>     Static Method     Public          Sets an Environment Variable
    <b>EXECUTE</b>     Static Method     Public          Starts an Application or Opens a Document in the Client
    <b>FILE_COPY</b>     Static Method     Public          Copies a File
    <b>FILE_DELETE</b>     Static Method     Public          Deletes a File

  • Read file from directory, update contents of the each file

    hai,
    I could not understand how to debug the error i have now.
    target
    1- read the files from directory // i able ot do this part
    2- for each file
    for each file read the content & compare with the existing List & update the list // i able to do this part
    when i try to combine both parts , i got some following error
    run:
    E:\java\check\100130.ixf
    Error: children[i] (The system cannot find the file specified)
    BUILD SUCCESSFUL (total time: 2 seconds)
    i can see from the code that children[i] only gives the error when i use that in the second part of the code.
    can any one help me on this??
    Thanks
    Priyan
    the original code
    import java.io.BufferedReader;
    import java.io.DataInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.InputStreamReader;
    import java.io.RandomAccessFile;
    import java.util.ArrayList;
    public class CompareList
         public static void main(String[] args){
             ArrayList a1 = new ArrayList();
             ArrayList a2 = new ArrayList();
             a1.add("1");
             a1.add("2");
             a1.add("3");
             a1.add("4");
             a1.add("5");
             a1.add("6");
             a1.add("7");
             a1.add("8");
             a1.add("9");
             a1.add("10");
             a1.add("11");
             a1.add("12");
             a1.add("13");
             a1.add("14");
             a1.add("15");
             a1.add("16");
             a1.add("17");
             a1.add("18");
             a1.add("19");
             a1.add("20");
             a1.add("21");
             a1.add("22");
             a1.add("23");
             a1.add("24");
             a1.add("25");
             a1.add("26");
             a1.add("27");
             a1.add("28");
             a1.add("29");
             a1.add("30");
             a1.add("31");
             a1.add("32");
             a1.add("33");
             a1.add("34");
             a1.add("35");
             a1.add("36");
             a1.add("37");
             a1.add("38");
             a1.add("39");
             a1.add("40");
             a1.add("41");
             a1.add("42");
             a1.add("43");
             a1.add("44");
             a1.add("45");
             a1.add("46");
             a1.add("47");
             a1.add("48");
             a1.add("49");
             a1.add("50");
             a1.add("51");
             a1.add("52");
              try{
                    File dir = new File("E:\\java\\check");
                    File[] children = dir.listFiles();
                    if (children == null) {
                          System.out.println("does not exist or is not a directory");
        else {
               for (int i = 0; i < children.length; i++) {
                       System.out.println( children);
    FileInputStream fstream = new FileInputStream("children[i]");
    DataInputStream in = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;
    while ((strLine = br.readLine()) != null)      {
    String line =strLine.substring(0,2);
    // Print the content on the console
    //System.out.println(line);
    a2.add(line);
    } // end of add list2
    if (a1.size() > a2.size())
    int k = 0;
    for (int l = 0; l < a2.size(); l++)
    if (!((String)a1.get(l)).equals((String)a2.get(l)))
    //System.out.println((String)a2.get(i));
    // System.out.println("dd");
    k = l;
    k++;
    for (int l = k; l < a1.size(); l++)
    System.out.println((String)a1.get(l));
    String str = "children[l]";
    File file = new File(str);
    RandomAccessFile rand = new RandomAccessFile(file,"rw");
    rand.seek(file.length()); //Seek to end of file
    rand.writeBytes((String)a1.get(i)); //Write end of file
    rand.writeBytes("., 0.");
    rand.writeBytes("\n");
    }// end of comparing and updating the list2
              in.close();
    catch (Exception e){//Catch exception if any
    System.err.println("Error: " + e.getMessage());

    thanks for the information.
    i tried, the error
    like this
    run:
    E:\java\check\100130.ixf
    java.lang.StringIndexOutOfBoundsException: String index out of range: 2
            at java.lang.String.substring(String.java:1935) 
            at CompareList.main(CompareList.java:84)
    BUILD SUCCESSFUL (total time: 0 seconds)this comes because in my code i used children[i] as string in the later part
        else {
               for (int i = 0; i < children.length; i++) {
                        System.out.println( children);
    FileInputStream fstream = new FileInputStream(children[i]);
    DataInputStream in = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;
    while ((strLine = br.readLine()) != null)      {
    String line =strLine.substring(0,2);
    a2.add(line);
    System.out.println(line);
    } // end of add list2
    if (a1.size() > a2.size())
    int k = 0;
    for (int l = 0; l < a2.size(); l++)
    if (!((String)a1.get(l)).equals((String)a2.get(l)))
    //System.out.println((String)a2.get(i));
    // System.out.println("dd");
    k = l;
    k++;
    for (int l = k; l < a1.size(); l++)
    System.out.println((String)a1.get(l));
    String str = "children[l]";
    File file = new File(str);
    RandomAccessFile rand = new RandomAccessFile(file,"rw");
    rand.seek(file.length()); //Seek to end of file
    rand.writeBytes((String)a1.get(i)); //Write end of file
    rand.writeBytes("., 0.");
    rand.writeBytes("\n");
    rand.close();
    }// end of comparing and updating the list2
              in.close();
    i stil could not figure out it yet. do u have any clue with this.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • "No such file or directory" errors on Time Machine backup volume

    I remotely mounted the Time Machine backup volume onto another Mac and was looking around it in a Terminal window and discovered what appeared to be a funny problem. If I "cd" into some folders (but not all) and do a "ls -la" command, I get a lot of "No such file or directory" errors for all the subfolders, but all the files look fine. Yet if I go log onto the Mac that has the backup volume mounted as a local volume, these errors never appear for the exact same location. Even more weird is that if I do "ls -a" everything appears normal on both systems (no error messages anyway).
    It appears to be the case that the folders that have the problem are folders that Time Machine has created as "hard links" to other folders which is something that Time Machine does and is only available as of Mac OS X 10.5 and is the secret behind how it avoids using up disk space for files that are the same in the different backups.
    I moved the Time Machine disk to the second Mac and mounted the volume locally onto it (the second Mac that was showing the problems), so that now the volume is local to it instead of a remote mounted volume via AFP and the problem goes away, and if I do a remote mount on the first Mac of the Time Machine volume the problem appears on the first Mac system that was OK - so basically by switching the volume the problem switches also on who shows the "no such file or directory" errors.
    Because of the way the problem occurs, ie only when the volume is remote mounted, it would appear to be an issue with AFP mounted volumes that contain these "hard links" to folders.
    There is utility program written by Amit Singh, the fella who wrote the "Mac OS X Internals" book, called hfsdebug (you can get it from his website if you want - just do a web search for "Mac OS X Internals hfsdebug" if you want to find it ). If you use it to get a little bit more info on what's going on, it shows a lot of details about one of the problematic folders. Here is what things look like on the first Mac (mac1) with the Time Machine locally mounted:
    mac1:xxx me$ pwd
    /Volumes/MyBackups/yyy/xxx
    mac1:xxx me$ ls -a
    . .DS_Store D2
    .. Documents D3
    mac1:xxx me$ ls -lai
    total 48
    280678 drwxr-xr-x 5 me staff 204 Jan 20 01:23 .
    282780 drwxr-xr-x 12 me staff 442 Jan 17 14:03 ..
    286678 -rw-r--r--@ 1 me staff 21508 Jan 19 10:43 .DS_Store
    135 drwxrwxrwx 91 me staff 3944 Jan 7 02:53 Documents
    729750 drwx------ 104 me staff 7378 Jan 15 14:17 D2
    728506 drwx------ 19 me staff 850 Jan 14 09:19 D3
    mac1:xxx me$ hfsdebug Documents/ | head
    <Catalog B-Tree node = 12589 (sector 0x18837)>
    path = MyBackups:/yyy/xxx/Documents
    # Catalog File Record
    type = file (alias, directory hard link)
    indirect folder = MyBackups:/.HFS+ Private Directory Data%000d/dir_135
    file ID = 728505
    flags = 0000000000100010
    . File has a thread record in the catalog.
    . File has hardlink chain.
    reserved1 = 0 (first link ID)
    mac1:xxx me$ cd Documents
    mac1:xxx me$ ls -a | head
    .DS_Store
    .localized
    .parallels-vm-directory
    .promptCache
    ACPI
    ActivityMonitor2010-12-1710p32.txt
    ActivityMonitor2010-12-179pxx.txt
    mac1:Documents me$ ls -lai | head
    total 17720
    135 drwxrwxrwx 91 me staff 3944 Jan 7 02:53 .
    280678 drwxr-xr-x 5 me staff 204 Jan 20 01:23 ..
    144 -rw-------@ 1 me staff 39940 Jan 15 14:27 .DS_Store
    145 -rw-r--r-- 1 me staff 0 Oct 20 2008 .localized
    146 drwxr-xr-x 2 me staff 68 Feb 17 2009 .parallels-vm-directory
    147 -rwxr-xr-x 1 me staff 8 Mar 20 2010 .promptCache
    148 drwxr-xr-x 2 me staff 136 Aug 28 2009 ACPI
    151 -rw-r--r-- 1 me staff 6893 Dec 17 10:36 A.txt
    152 -rw-r--r--@ 1 me staff 7717 Dec 17 10:54 A9.txt
    So you can see from the first few lines of the "ls -a" command, it shows some file/folders but you can't tell which yet. The next "ls -la" command shows which names are files and folders - that there are some folders (like ACPI) and some files (like A.txt and A9.txt) and all looks normal. And the "hfsdebug" info shows some details of what is really happening in the "Documents" folder, but more about that in a bit.
    And here are what a "ls -a" and "ls -al" look like for the same locations on the second Mac (mac2) where the Time Machine volume is remote mounted:
    mac2:xxx me$ pwd
    /Volumes/MyBackups/yyy/xxx
    mac2:xxx me$ ls -a
    . .DS_Store D2
    .. Documents D3
    mac2:xxx me$ ls -lai
    total 56
    280678 drwxr-xr-x 6 me staff 264 Jan 20 01:23 .
    282780 drwxr-xr-x 13 me staff 398 Jan 17 14:03 ..
    286678 -rw-r--r--@ 1 me staff 21508 Jan 19 10:43 .DS_Store
    728505 drwxrwxrwx 116 me staff 3900 Jan 7 02:53 Documents
    729750 drwx------ 217 me staff 7334 Jan 15 14:17 D2
    728506 drwx------ 25 me staff 806 Jan 14 09:19 D3
    mac2:xxx me$ cd Documents
    mac2:Documents me$ ls -a | head
    .DS_Store
    .localized
    .parallels-vm-directory
    .promptCache
    ACPI
    ActivityMonitor2010-12-1710p32.txt
    ActivityMonitor2010-12-179pxx.txt
    mac2:Documents me$ ls -lai | head
    ls: .parallels-vm-directory: No such file or directory
    ls: ACPI: No such file or directory
    ... many more "ls: ddd: No such file or directory" error messages appear - there is a one-to-one
    correspondence between the "ddd" folders and the "no such file or directory" error messages
    total 17912
    728505 drwxrwxrwx 116 me staff 3900 Jan 7 02:53 .
    280678 drwxr-xr-x 6 me staff 264 Jan 20 01:23 ..
    144 -rw-------@ 1 me staff 39940 Jan 15 14:27 .DS_Store
    145 -rw-r--r-- 1 me staff 0 Oct 20 2008 .localized
    147 -rwxr-xr-x 1 me staff 8 Mar 20 2010 .promptCache
    151 -rw-r--r-- 1 me staff 6893 Dec 17 10:36 A.txt
    152 -rw-r--r--@ 1 me staff 7717 Dec 17 10:54 A9.txt
    If you look very close a hint as to what is going on is obvious - the inode for the Documents folder is 152 on the local mounted case (the first set of code above for mac1), and it's 728505 in the remote mounted case for mac2. So it appears that these "hard links" to folders have an extra level of folder that is hidden from you and that AFP fails to take into account, and that is what the "hfsdebug" shows even better as you can clearly see the REAL location of the Documents folder is in something called "/.HFS+ Private Directory Data%000d/dir_135" that is not even visible to the shell. And if you look closely in the remote mac2 case, when I did the "cd Documents" I don't go into the inode 135, but into the inode 728505 (look close at the "." entry for the "ls -la" commands on both mac1 and mac2) which is the REAL problem, but have no idea how to get AFP to follow the extra level of indirection.
    Anyone have any ideas how to fix this so that "ls -l" commands don't generate these "no such file or folder" messages?
    I am guessing that the issue is really something to do with AFP (Apple File Protocol) mounted remote volumes. The TimeMachine example is something that I used as an example that anyone could verify the problem. The real problem for me has nothing to do with Time Machine, but has to do with some hard links to folders that I created on another file system totally separate from the Time Machine volume. They exhibit the same problem as these Time Machine created folders, so am pretty sure the problem has nothing to do with how I created hard links to folders which is not doable normally without writing a super simple little 10 line program using the link() system call - do a "man 2 link" if you are curious how it works.
    I'm well aware of the issues and the conditions when they can and can't be used and the potential hazards. I have an issue in which they are the best way to solve a problem. And after the problem was solved, is when I noticed this issue that appears to be a by-product of using them.
    Do not try these hard links to folders on your own without knowing what they're for and how to use them and not use them. They can cause real problems if not used correctly. So if you decide to try them out and you loose some files or your entire drive, don't say I didn't warn you first.
    Thanks ...
    -Bob

    The problem is Mac to Mac - the volume that I'm having the issue with is not related in any way to Time Machine or to TimeCapsule. The reference to TIme Machine is just to illustrate the problem exists outside of my own personal work with hard links to folders on HFS Extended volumes (case-sensitive in this particular case in case that matters).
    I'm not too excited about the idea of snooping AFP protocol to discover anything that might be learned there.
    The most significant clue that I've seen so far has to do with the inode numbers for the two folders shown in the Terminal window snippets in the original post. The local mounted case uses the inode=728505 of the problematic folder which is in turn linked to the hidden original inode of 135 via the super-secret /.HFS+... folder that you can't see unless using something like the "hfsdebug" program I mentioned.
    The remote mounted case uses the inode=728505 but does not make the additional jump to the inode=135 which is where lower level folders appear to be physically stored.
    Hence the behavior that is seen - the local mounted case is happy and shows what would be expected and the remote mounted case shows only files contained in the problem folder but not lower-level folders or their contents.
    From my little knowledge of how these inode entries really work, I think that they are some sort of linked list chain of values, so that you have to follow the entire chain to get at what you're looking for. If the chain is broken somewhere along the line or not followed correctly, things like this can happen. I think this is a case of things not being followed correctly, as if it were a broken chain problem then the local mounted case would have problems also.
    But the information for this link in the chain is there (from 728505 to the magic-135) but for some reason AFP doesn't make this extra jump.
    Yesterday I heard back from Apple tech support and they have confirmed this problem and say that it is a "implementation limitation" with the AFP client. I think it's a bug, but that will have to be up to Apple to decide now that it's been reported. I just finished reporting this as a bug via the Apple Bug Reporter web site -- it's bug id 8926401 if you want to keep track it.
    Thanks for the insights...
    -Bob

Maybe you are looking for

  • How to add XML attribute to an Element using BPEL assign

    I have a request xml to a bpel process that does not contain a attribute. After some process I need to create this missing attribute and set a value. I tried using the XML fragment in the Assign Activity. But how can I create a attribute? This XML no

  • A strange error about cursor and dblink

    My dbms:Oracle8i Enterprise Edition Release 8.1.7.4.0 I have a stored procedure, which inserts records from a remote database into a local table. The 'insert' statement have similar pattern: insert into table_a select table_b.columns from table_b@dbl

  • PSE 9 Editor crashes at start up

    Hoping someone can help! I've recieved the PSE9 brand new out of the box, and installed with no problems. I am able to open the organizer, but the editor crashes everytime I try to open it (from the start up menu as well as the organizer). I recieve

  • PC Suite claims phone not detected on Sync

    Hi, I'm using an E71 with the latest update of PC Suite on a work networked PC using XP Professional. Until yesterday I was syncing through USB with no problems... Yesterday although my device is connecting to the computer and syncs the image files w

  • Searching for costcenter "7890"  in all cubes/ods

    hi gurus i am looking for a costcenter "7890" in all the cubes/ods. now the simple way is to manage the cube and look into its contents but that is taking very long and i have 100's of cubes, so is there some way i can find where this masterdata is b