Java File IO getCanonicalFile() handling Linux Symbolic links

Does anyone have any experience using the File.getCanonicalFile() method. I would prefer to use the getCanonicalFile() to obtain the real file pointed to by a symbolic link, rather than the Linux "ls" command.
I currently check for any changes by executing a "ls" every second,when I test the getCanonicalFile() method, I see he doesn't seem to keep up with the real situation on the FileSystem ?
Example:
2009-04-28 13:56:57:575 [00000] TEST: ls file=/ama/log/PPT/ape/feAPE_090428_135651 getCanonicalFile()=/ama/log/PPT/ape/feAPE_090428_135627
2009-04-28 13:56:58:569 [00000] TEST: ls file=/ama/log/PPT/ape/feAPE_090428_135651 getCanonicalFile()=/ama/log/PPT/ape/feAPE_090428_135627
2009-04-28 13:56:59:594 [00000] TEST: ls file=/ama/log/PPT/ape/feAPE_090428_135651 getCanonicalFile()=/ama/log/PPT/ape/feAPE_090428_135627
2009-04-28 13:57:00:592 [00000] TEST: ls file=/ama/log/PPT/ape/feAPE_090428_135651 getCanonicalFile()=/ama/log/PPT/ape/feAPE_090428_135627
2009-04-28 13:57:01:543 [00000] TEST: ls file=/ama/log/PPT/ape/feAPE_090428_135651 getCanonicalFile()=/ama/log/PPT/ape/feAPE_090428_135627
2009-04-28 13:57:02:503 [00000] TEST: ls file=/ama/log/PPT/ape/feAPE_090428_135701 getCanonicalFile()=/ama/log/PPT/ape/feAPE_090428_135627
2009-04-28 13:57:04:058 [00000] TEST: ls file=/ama/log/PPT/ape/feAPE_090428_135701 getCanonicalFile()=/ama/log/PPT/ape/feAPE_090428_135627
2009-04-28 13:57:04:460 [00000] TEST: ls file=/ama/log/PPT/ape/feAPE_090428_135701 getCanonicalFile()=/ama/log/PPT/ape/feAPE_090428_135627
2009-04-28 13:57:05:526 [00000] TEST: ls file=/ama/log/PPT/ape/feAPE_090428_135701 getCanonicalFile()=/ama/log/PPT/ape/feAPE_090428_135701
2009-04-28 13:57:06:546 [00000] TEST: ls file=/ama/log/PPT/ape/feAPE_090428_135701 getCanonicalFile()=/ama/log/PPT/ape/feAPE_090428_135701
Thx.

Hi ejp, nice picture :) .
The task:
Trying to count specific records in a log file (A type of modified Linux tail). I've tried to use the symbolic name as the original filename (FileInputStream) but when the file gets switched (link deleted and recreated) the fileDescriptor knows nothing about the new file, no changes are ever seen.
So basically, how can I track the latest "real" log file ? I'm using "ls" every iteration, If the filename changes, I close the current stream and open new one?
I've also tested using "new File(...)" and using a Filter on the list output but this is slower than the "ls". I hoped getCannonicalFile() was the answer.
            // Close the current Buffered Input stream
            is.close();
            // Open a new buffered input stream with the NEW Filename
            is = new BufferedInputStream(new FileInputStream(filename));
            // Log the details of the found file
            sp.getLog().msg(clientBean.getPort(), "Tracking new filename: " + filename + " InputStream Found available to read: " + is.available());
            // Connect the Input stream to a Data input stream
           dis = new DataInputStream(is);

Similar Messages

  • Does TM backup files pointed to from a symbolic link?

    I was just wondering if TM would backup files that are pointed to by a symbolic link or some such alias?
    It would be a way to make TM backup files it would ordinarily skip, such as files on another drive or even computer.
    Just a though and a question.

    I would imagine that TimeMachine uses similar API's to Spotlight, in which case all filesystem writes are noted, regardless of the source.
    Unfortunately, I can't confirm this until I've got TM working with my network file server
    --Andrew

  • RemoteApp File Paths do not support Symbolic Links

    Has anyone gotten RemoteApp to work with symbolic links?
    I have an application in C:\app\1.0 . I have a symbolic link C:\app\latest that points to the 1.0 folder. When I publish the application through the GUI, it stores the path as C:\app\1.0 rather than C:\app\latest. If I use a PowerShell Command, it will store
    the symbolic link version of the path, but the application will fail to open.

    Hi,
    Thank you for posting in Windows Server Forum.
    As per my research, I can say that it supports the symbolic link for RemoteApp. But please check that you have placed the correct path links for RemoteApp to use. As when RemoteApp used the symbolic link, we must have the path link correct which will open the
    application.
    Also please see that you have latest version of client RDP installed, RDP 8.1.
    Hope it helps!
    Thanks.
    Dharmesh Solanki
    TechNet Community Support

  • Java Home symbolic links broken

    I followed a tutorial to install Tomcat on Mac OS X. When running, I got an error saying /Library/Java/Home/bin/java: No such file or directory. After going to /Library/Java, I saw that Home was a broken symbolic link to /System/Library/Frameworks/JavaVM.framework/Home. So, going to /System/Library/Frameworks/JavaVM.framework I saw that the Home file there was a broken symbolic link to /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home. As you could guess, CurrentJDK was a broken symbolic link to /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents, and /System/Library/Java/JavaVirtualMachines/ doesn't even exist. Where should I set all of these to?

    Have you installed Java yet on Lion?
    http://support.apple.com/kb/DL1421

  • Symbolic links on samba network drives broken?

    Note: I first posted this in Apple.com > Support > Discussions > Mac OS X v10.5 Leopard > Using Mac OS X Leopard where it was suggested I post here. In my readings it looks like 10.6 may solve some of this but I'm not sure.
    I'm seeing the following sort of behaviour on all of the macs I have tested in the following configuration:
    Network file server:
    Solaris 10
    samba 3.4.2
    Macs:
    Leopard 10.5.6
    Connect to exported folders via smb in finder "connect to server". In the examples below abc123 is a remote folder.
    Open terminal and try the following tests:
    1. Attempting to remove a symbolic link fails.
    * cd /Volumes/abc123/tmp
    * touch foo
    * ln -s foo .bar # this works
    * rm .bar # fails with no message
    * rm foo # succeeds
    * rm .bar # fails with no message
    If the symbolic link is to a socket then you at least get a message when rm fails ("rm: .parentlock: No such file or directory" as an example for a link created on the remote drive by Thunderbird or Firefox).
    2. Removing linked file removes unlinked file??
    * touch foo
    * ln -s foo bart
    * touch ._bart
    * ls -la # observe that ._bart exists
    * rm bart
    * ls -la # observe that bart still exists, but that ._bart is gone!!!
    3. Removing linked file does not work.
    * ln -s bart ._bart
    * rm bart # fails
    4. Hard links do not delete either.
    * touch foo
    * ln foo ._bart
    * rm foo
    * ln -s bar ._bart # ln: ._bart: File exists
    * rm ._bart # rm: ._bart: No such file or directory
    5. Symbolic links are copied instead of the file contents.
    * touch foo
    * ln -s foo ._blaht
    * cp ._blaht /tmp
    and observe that, in /tmp, you have "._blaht -> foo" instead of the actual file.
    So can anyone else reproduce any of the above problems? In my limited searching for samba related problems I did not see any posting about this type of situation. Also, everything works just fine on local drives.

    Depending on the filesystem, Mac OS X creates ._foo files when you create a foo file, so you'll probably have to live with that. For example, for each file on my FAT32-formatted USB flash drive there is a ._xxx file. Others may be able to explain what these things are. I'm pretty sure they contain file metadata, perhaps like .DS_Store files created for other file systems.

  • Does Java/JVm have a way to ditinguish between real files and Symbolic link

    Hello guys,
    I am using java.io.File.listFiles to list files in a directory. I have a symbolic link in the directory. the "listFiles" listing symbolic file contents too. As the real directory Symbolic link pointing is huge, the application taking too much time to load. is it a normal behaviour? are there any work arounds?

    Short version: If getCannonicalPath() and getAbsolutePath() return different values, then the file you look at is a symlink.
    [longer version|http://www.idiom.com/~zilla/Xfiles/javasymlinks.html]

  • HOW TO INSTALL JDK1.4 ON LINUX PALTFORM AND HOW TO COMPILE A JAVA  FILE

    SIR PLZ KINDLY TELL ME THE PROCDURE OF INSTALL JSDK1.4 ON LINUX .
    1.I HAVE DOWNLOADED IT ONA I HAVE INSTALL IN
    /usr/local
    but
    2: do nt know how set the CALSSPATH and JAVA_HOME(ENV VARIABLES)
    3:HOW TO COMPILE AND RUN THE JAVA FILE(JSP)

    2.
    export JAVA_HOME=/usr/local/jdk1.4.0
    export CLASSPATH=.
    (amending for your set up.)
    Placing these in your /etc/profile file will make them run automatically on log in of a user.
    3.
    You need tomcat, probably, http://jakarta.apache.org.
    Bhav

  • Can I use symbolic links to share abook.mab file for two users

    If I delete any of the .mab files from one user profile and replace it with a symbolic link that points to the same file in the other profile will this synchronise my address books for the two profiles. I have win7.
    The object is to have two Windows User accounts sharing all the same email data. I have already have them pointed at the same message store.
    I also wish to know if deleting a .mab file will only cause it to be re-created.
    I am hesitant to experiment.
    Thanks

    Deleting any of the two default mab files, abook.mab (Personal Address Book) or history.mab (Collected Addresses) will result in new, empty files with these names being recreated automatically when TB is restarted.
    There are some ideas for sharing address books here:
    http://kb.mozillazine.org/Sharing_address_books

  • Java exception appear during file adapter to handle large xml

    Hi,Guys,
    I am using file adapter to poll one folder of my local.one get input.xml,then do something,then write out output.xml.
    input.xml format is :
    <mes:DataRequestIns xmlns:mes="http://xml.netbeans.org/schema/MessageDefined">
    <!--1 or more repetitions:-->
         <mes:DataIns>
              <mes:address>Ang Mo Kio 5,63 street</mes:address>
              <mes:birthday>14/12/1970</mes:birthday>
              <mes:firstName>Sing1</mes:firstName>
              <mes:gender>0</mes:gender>
              <mes:ID>1001</mes:ID>
              <mes:lastName>NorthMan</mes:lastName>
              <mes:postcode>2002</mes:postcode>
              <mes:telephone>6665222</mes:telephone>
              <mes:surname>Sur</mes:surname>
              <mes:status>single</mes:status>
              <mes:location>sgp</mes:location>
              <mes:HP1>11111</mes:HP1>
              <mes:HP2>22222</mes:HP2>
              <mes:passport>123456878</mes:passport>
              <mes:company>ST</mes:company>
              <mes:department>TO</mes:department>
              <mes:occupation>engineer</mes:occupation>
              <mes:experience>10</mes:experience>
              <mes:level>2</mes:level>
              <mes:certificate>high</mes:certificate>
              <mes:specialisation>computer</mes:specialisation>
              <mes:staffNumber>1020</mes:staffNumber>
              <mes:fax>00200</mes:fax>
              <mes:email>[email protected]</mes:email>
              <mes:national1>sgp</mes:national1>
              <mes:national2>sgp</mes:national2>
              <mes:interestingField>bpel</mes:interestingField>
              <mes:national>earth</mes:national>
              <mes:oversea>yes</mes:oversea>
         </mes:DataIns>
    <mes:DataIns>
    </mes:DataIns>
    </mes:DataRequestIns>
    if my input.xml contain less than 1000 records,then it's working,once greater than 1000,then appear exception.for normal case ,must have more than 10000 records need to handle,and file size is 11.2MB.
    so,Does any other way or how to use file adapter to handle it ?
    thank you
    exception :
    SEVERE: An error occured while scanning for the next trigger to fire.
    org.quartz.JobPersistenceException: Failed to obtain DB connection from data sou
    rce 'soaNonManagedDS': java.sql.SQLException: Could not retrieve datasource via
    JNDI url 'jdbc/SOALocalTxDataSource' weblogic.jdbc.extensions.ConnectionDeadSQLE
    xception: weblogic.common.resourcepool.ResourceDeadException: 0:weblogic.common.
    ResourceException: Could not create pool connection. The DBMS driver exception w
    *as: Socket read timed out [See nested exception: java.sql.SQLException: Could no*
    *t retrieve datasource via JNDI url 'jdbc/SOALocalTxDataSource' weblogic.jdbc.ext*
    *ensions.ConnectionDeadSQLException: weblogic.common.resourcepool.ResourceDeadExc*
    *eption: 0:weblogic.common.ResourceException: Could not create pool connection. T*
    *he DBMS driver exception was: Socket read timed out]*
    at org.quartz.impl.jdbcjobstore.JobStoreCMT.getNonManagedTXConnection(Jo
    bStoreCMT.java:167)
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLoc
    k(JobStoreSupport.java:3652)
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.acquireNextTrigger(JobSt
    oreSupport.java:2654)
    at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:
    *235)*
    Caused by: java.sql.SQLException: Could not retrieve datasource via JNDI url 'jd
    bc/SOALocalTxDataSource' weblogic.jdbc.extensions.ConnectionDeadSQLException: we
    blogic.common.resourcepool.ResourceDeadException: 0:weblogic.common.ResourceExce
    ption: Could not create pool connection. The DBMS driver exception was: Socket r
    ead timed out
    another exception:
    Message handle error.
    error while attempting to process the message "com.collaxa.cube.engine.dispatch.
    message.invoke.InvokeInstanceMessage"; the reported exception is: Transaction Ro
    lledback.: weblogic.transaction.internal.TimedOutException: Transaction timed ou
    t after 302 seconds
    BEA1-3468FC5E3C698D2A82F7
    at weblogic.transaction.internal.ServerTransactionImpl.wakeUp(ServerTran
    sactionImpl.java:1742)
    at weblogic.transaction.internal.ServerTransactionManagerImpl.processTim
    edOutTransactions(ServerTransactionManagerImpl.java:1609)
    at weblogic.transaction.internal.TransactionManagerImpl.wakeUp(Transacti
    onManagerImpl.java:1885)
    at weblogic.transaction.internal.ServerTransactionManagerImpl.wakeUp(Ser
    verTransactionManagerImpl.java:1519)
    at weblogic.transaction.internal.WLSTimer.timerExpired(WLSTimer.java:35)
    at weblogic.timers.internal.TimerImpl.run(TimerImpl.java:273)
    at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTunin
    gWorkManagerImpl.java:516)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
    *; nested exception is: weblogic.transaction.internal.TimedOutException: Transact*
    ion timed out after 302 seconds
    BEA1-3468FC5E3C698D2A82F7
    This error contained an exception thrown by the message handler.
    Edited by: aris yu on Dec 27, 2009 11:55 PM

    Hi,
    we have to explicitly mention batch while configuaring file adapter.
    i.e. in step 5 : Check file contains multiple messages and mention how many messages u want to process in a batch.
    i.e. if you have 10000 msgs in ur file mention the size as 500. Then it will read 10000 records in 20 batches.
    Now while writing to a file use Append=true property.
    U have to add this property to fileadapter.wsdl (in jca:operation tag) which will be created when u complete the configuaration of file adapter with write operation.
    Regards
    PavanKumar.M

  • Java files linked in notepad

    I opened a java file in notepad. however, i did not uncheck the always associate too notepad. now all the java files are linked to notepad. should i disassociate java files from notpad by going into view type in windows folder tools or is it safe to leave them to link to notepad?

    codesamurai wrote:
    I opened a java file in notepad. however, i did not uncheck the always associate too notepad. now all the java files are linked to notepad. should i disassociate java files from notpad by going into view type in windows folder tools or is it safe to leave them to link to notepad?it is perfectly safe...

  • Java - too many levels of symbolic links

    Hi everyone,
    Today I've tried to launch eclipse and I noticed this strange error :
    [^81%][11:12][cafe][~]$ eclipse
    /usr/bin/java: line 2: /usr/lib/jvm/default/bin/java: Too many levels of symbolic links
    /usr/bin/java: line 2: exec: /usr/lib/jvm/default/bin/java: cannot execute: Too many levels of symbolic links
    Inspecting the /usr/lib/jvm folder revealed the issue:
    [^82%][11:14][cafe][~]$ cd /usr/lib/jvm
    [^82%][11:15][cafe][jvm]$ ls -lhA
    total 4.0K
    lrwxrwxrwx 1 root root 7 Sep 5 11:12 default -> default
    lrwxrwxrwx 1 root root 11 Sep 4 16:44 default-runtime -> default/jre
    drwxr-xr-x 3 root root 4.0K Jul 3 16:02 java-7-openjdk
    lrwxrwxrwx 1 root root 7 Sep 4 16:44 java-default-runtime -> default
    So I've just removed the default symbolic link and replaced with :
    [^82%][11:15][cafe][jvm]$ sudo rm default
    [^84%][11:16][cafe][jvm]$ sudo ln -s java-7-openjdk/jre default
    [^84%][11:17][cafe][jvm]$ ls -lhA
    total 4.0K
    lrwxrwxrwx 1 root root 18 Sep 5 11:17 default -> java-7-openjdk/jre
    lrwxrwxrwx 1 root root 11 Sep 4 16:44 default-runtime -> default/jre
    drwxr-xr-x 3 root root 4.0K Jul 3 16:02 java-7-openjdk
    lrwxrwxrwx 1 root root 7 Sep 4 16:44 java-default-runtime -> default
    and now eclipse launches without any issues.
    So I ask, is this the correct behavior? and..
    Why do we have so many symbolic links in this folder?
    Cheers,

    https://bbs.archlinux.org/viewtopic.php … 4#p1453804

  • Does ucf.jar handle symbolic links?

    When bulding a .zxp package using ucf.jar on the command line, I wish to package symbolic links which point at files which are not necessarily here on my system - they point at elements which will be installed as part of the extension.
    When ucf.jar encounters such a symbolic link, however, it stops, saying “no such file” with the name of the link.
    Is this expected behaviour? If so, when will this bug be fixed? Let me know if more details are required!

    If the file exists, then the pointed-to files are packaged, instead of the symbolic link itself, which is not what I'm after either; this is a link which will be correct on the destination after the bundle is unpacked, but which may not yet be present on the system doing the packaging. I think this may be related to http://forums.adobe.com/message/4681087#4681087 , though it is not exactly the same problem.
    Perhaps to rephrase my question then:
    How may I package a symbolic link using ucf.jar?
    At the moment there are two options:
    • Destination pointed to by link does not exist -> failure with “file not found”.
    • Destination pointed to by link does exist -> package is built containing the destination file, not the symbolic link.
    Neither of these behaviours is what I want: I want to package the link!

  • What are the names ( or a link to them) of Java files I should have? Thanx in advance.

    What are the names (or a link to them) of Java files I should have installed? Thanx in advance.

    This doesn't make sense.  It's more complicated than that.
    OS X will offer to install Java if you need it, unless you've gone in and deleted stuff and made a mess of things.  Did you manually go deleting stuff?

  • Symbolic Link doesn't work in 'File Window' on Mac

    Hi, I'm Nao from Japan.
    I'm sorry for my strange English.
    I usually use Dreamweaver CC on Windows7 PC.
    I manage some web sites. Three of them belong to same group. They require some same image files. The three sites are on one remote web server. So I use symbolic link(directory) to share the image files.
    And on my windows PC, I use symbolic link to share the files in the local sites of the three.
    'File Window' of dreamweaver CC (for Win) understands symbolic link and i have no trouble.
    But 'File Window' of dreamweaver CC (for Mac) can't understand symbolic link.
    ('Preview Window' understand symbolic link.)
    How can i solve the issue?

    Thank you for your reply.
    I should explain my situation again.
    at command prompt on windows7,
    c:\webSites>mkdir site_A
    c:\webSites>mkdir site_B
    c:\webSites>mkdir site_A\shared_images
    c:\webSites>mklink /d site_B\shared_images c:\webSites\site_A\shared_images\
    'c:\webSites\site_B\shared_images\' acts right on File Window of Dreamweaver CC.
    If some files are put into the 'c:\webSites\site_A\shared_images\' ,they will appear in 'c:\webSites\site_B\shared_images\' on File Window of Dreamweaver CC.
    but at terminal on Mac OSX,
    MacBookPro:webSites nao$ mkdir site_A
    MacBookPro:webSites nao$ mkdir site_B
    MacBookPro:webSites nao$ mkdir site_A/shared_images
    MacBookPro:webSites nao$ ln -s /(somewhere)/webSites/site_A/shared_images/ site_B/shared_images
    '/(somewhere)/webSites/site_B/shared_images/' doesn't act right on File Window of Dreamweaver CC.
    But '/(somewhere)/webSites/site_B/shared_images/' acts right on 'Finder'.
    And in the 'Design view', the images located in '/(somewhere)/webSites/site_B/shared_images/' are displayed right.
    I am at a loss.

  • How to link two .java files together?

    hello everybody,
    is it possible to link two or more .java files together? I mean is if I have 3 .java files. (a.java, b.java, c.java) then I have 3 .class files too. How do I use the method in other .java files. For example :
    public a extends Applet {
    // call b.class
    b();
    public b extends Applet implements ActionListener {
    void title1() {
    How to call the b.class? How to call the title1() method?
    Is it related to JAR or package??
    Thanks for helping me. v(^_^)v

    O.K, you do not link ".java" files together.
    You compile them into class files and they can create new instances of each other and and access their variables and work together.
    I recommend "Sam's Teach Yourself Java in 21 Days".
    It will start you out with the basics.
    --Ian                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

Maybe you are looking for

  • Links in Discoverer Reports

    I am new to Discoverer Reports so i want know, how to implement links in discoverer reports, I have two worksheets/links/pages in a Discoverer Report, in the first worksheet/page some data will be displayed, i want to display links for a particular c

  • The iPod "my ipod name" cannot be updated. The required file is in use.

    Installed iTunes 7 on my mac. Everything went fine. Updated my ipod everything went fine. Ever since then I've been getting a dialogue pop up window stating "The iPod "my ipod name" cannot be updated. The required file is in use." This pop up happens

  • Background Scheduling Via SE38

    Hello. I am trying to stop some transactions of being executed in dialog mode. My intention is to force the end user to use the background processing instead. But even with the background processing I have a problem. I must force the users just to us

  • TS1538 Connecting Iphone to Itunes

    Hello, I just wanted to back -up my Iphone on Itunes as usual, but my Iphone does not come up in the Itunes sidebar and it is not connecting. The Iphone is connected to Windows fine, the Apple Mobile Device is running correctly, my USB cable is fine,

  • I click on layouts and still cannot change book size

    I'm trying to change the size of the ibook before I buy it. I've tried several options buy cannot figure it out. Any help would be appreciated.