How to check a text file is already opened by another process

Hi All,
  We are facing a requirement to check a simple text file that has been already opened by some other process using java programming.We are using simple file reading concepts to read the content of those text file
  For eg: Let us take sample.txt in any of the system location which is manually opened and we need to check that sample.txt is opened or not using java programming.
              If it is not opened by any process then only we should  read that file otherwise we shouldn't.
ANY GUIDANCE WILL BE HELPFUL...
Thanks & Regards,
Rumeshbabu

Hi Christian,
Thanks. Our scenario is...
1. We have log files(in.txt) which is scheduled everyday for tracking and the scheduler will be writing the file ,it will be closed by night 11.
2.So in case if we write any java code to access that log file(using  io file concept in java) we need access to that log file from our standalone java program only after night 11 0 clock.
3.So we should check a condition whether that log file has been already used by some other process.
Thanks & Regards.
Rumeshbabu

Similar Messages

  • This file is already open by another user or another application-

    I am using InDesign CS4 on Mac OS 10.6.4, and sporadically get an error message reading "This file is already open by another user or another application. This file may be stored on a network server and cannot be opened until the other user closes it." This happens when I try to open a saved .indd file. The files are all on my hard drive, I created them, and nobody else has access to them.
    So far I've lost a handful of files' worth of work, as I cannot open the file in InDesign as an original or a copy, nor can I copy the file in the Finder (I get "unknown error: -22"), nor can I copy or move it using Terminal, nor can I zip it up. Time Machine doesn't recognize the file, and Apple Support couldn't help.
    I tried calling Adobe Support, but after telling me it was $40 for the answer the phone tech sent me back to the website instead of letting me pay!
    How do I fix this? I am losing hours of client work every time this happens, and only if I have a pdf version of the file can I recreate the work.
    Many thanks in advance.

    The last time it happened I restarted, cleared both the PRAM and NVRAM, and ran both Disk Utility and Disk Warrior. Nothing fixed it. I changed the permissions a number of times and that did not fix it.
    It's important to note that it doesn't happen to every file I save from InDesign; if it did I would have re-installed CS3 and dealt with that, because this issue never happened before I upgraded. So there's also no way to know if a possible fix is working or not.
    Also, there were no placed images or other artwork in the file this happened to most recently.
    I've checked my FontCase prefs, and if it's not running it's disabled, so that's out. I have some fonts that had been converted from Windows PostScript to TrueType, so I've disabled those.
    As I mentioned in the original post, I am not on a network beyond my home network, which consists of two computers and two routers. The file is on my computer's hard drive, and I am the only person accessing it. While I do use Dropbox, this file is not in that directory.

  • How to check if a file is being read by another program?

    Hey all,
    I just have a few question for a project I am doing:
    How do I check if a file is being read by another program?
    How do I check how many lines it read?
    How do I get Keyboard input from the user when he is using another program other than mine? Ex: Pressing Ctrl-G to take a screenshot.
    How can I halt another program from reading a file when it already opened it? Ex: The other program opened a file and began reading. Now it is at line 2 and I want to make it skip 10 lines and contontinue.
    Thanks,
    Bluelikeu

    How do I check if a file is being read by another
    program?This is about the only partially sensible question you asked. But the answer is that unless you use some native code, you can't.
    How do I check how many lines it read?It doesn't even make sense to ask this question. First of all, what's a "line" anyway? Files are just sequences of bytes. A "line" is only in the interpretation of those bytes, such as if it contains <cr><lf> sequences an application may choose to render the contents of those bytes as logical "lines" of string sequences. Second of all, why the heck would it matter to you how many bytes have already been read by some other process(es)?
    How do I get Keyboard input from the user when he is
    using another program other than mine? Ex: Pressing
    Ctrl-G to take a screenshot.You want to spy on other applications? Shame on you, Mr. Spyware creator.
    How can I halt another program from reading a file
    when it already opened it? Ex: The other program
    opened a file and began reading. Now it is at line 2
    and I want to make it skip 10 lines and contontinue.Shame on you Mr. Spyware creator.

  • Function module to check if a file is already open

    Hi All,
    Could any one of you tell me a function module which checks whether a given file on the application server is currently being open or not.
    Regards
    Amit Mishra

    Amit,
    Try GET DATASET.
    Basic form
    GET DATASET dsn.
    Extras:
    1. ... POSITION pos
    2. ... ATTRIBUTES attr
    In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs. For details, see File Interface.
    Effect
    Used to get the properties of a file already open.
    You can use this statement without additions to determine whether the file is open.
    If the file is not open, an exception of the type CX_SY_FILE_OPEN_MODE is triggered.
    Regards,
    Rao A
    Message was edited by: Rao Arimilli

  • How to tell if a file is being used by another process?

    Thanks to nrlz for helping me with my last question http://forum.java.sun.com/thread.jsp?forum=31&thread=387999&tstart=15&trange=15 i have been able to make my virtual folder containing folders :) sort of a tounge twister :)
    However i have had to put in a 1 second delay before running the script after i create it otherwise the script will fail as it thinks the file is still being used by the java program.
    I wish to know how to test for wether a file is currently locked by a process (with out trying to create a File() instance in a try/catch block as this would lock the file again :/ )
    the program is below.
    If you are using win98 you may need to change:
    Runtime.getRuntime().exec("c:\\winnt\\system32\\wscript.exe \"createShorcut.vbs\"");
    to
    Runtime.getRuntime().exec("c:\\windows\\system32\\wscript.exe \"createShorcut.vbs\"");
    you will need a file called directories.ini with the following format:
    <directory that will hold the shortcuts>
    <directory 1>
    <directory 2>
    <directory n>
    END
    example
    --->file start<---
    c:\root
    c:\
    d:\
    f:\apps\
    g:\games\
    END
    --->file end<----
    import java.io.*;
    class winVirtualFolder
         public static void main (String args[]) throws IOException, InterruptedException
               File inFile = new File("directories.ini");
             FileReader fileReader = new FileReader(inFile);
             BufferedReader bufReader = new BufferedReader(fileReader);
             String str="";
                   String home="";
                   winVirtualFolder wVF=new winVirtualFolder();
             home= bufReader.readLine();
                   str=bufReader.readLine();
                   System.out.println("HOME DIR: "+home);
                   while (!str.equals("*END*"))
                        System.out.println("***STR: "+str);
                        wVF.createShortcuts(str,home);
                        str=bufReader.readLine();
         void createShortcuts(String path,String home) throws IOException, InterruptedException
              File directory= new File(path);
              String[] listing =directory.list();
              File[] fileListing =directory.listFiles();
              String[] directories= new String[listing.length];
              for (int i=0;i<listing.length;i++)
                   System.out.print(listing);
                   if (fileListing[i].isDirectory())
                        System.out.println(" DIRECTORY");
              File outFile = new File("createShorcut.vbs");
              FileWriter fileWriter = new FileWriter(outFile);
                   BufferedWriter bufWriter = new BufferedWriter(fileWriter);
                        bufWriter.write("set WshShell = WScript.CreateObject(\"WScript.Shell\")\r\n");
                        bufWriter.write("set oShellLink = WshShell.CreateShortcut(\""+home+""+listing[i]+".lnk\")\r\n");
                        bufWriter.write("oShellLink.TargetPath = \""+path+""+listing[i]+"\\\"\r\n");
                        bufWriter.write("oShellLink.Description = \""+listing[i]+"\\\"\r\n");
                        bufWriter.write("oShellLink.Save\r\n");
              bufWriter.close();
                        sleep(1000);
                        Runtime.getRuntime().exec("c:\\winnt\\system32\\wscript.exe \"createShorcut.vbs\"");
                   else System.out.println("");
         void sleep (long time)
              long waitValue=System.currentTimeMillis()+time;
              while (System.currentTimeMillis()<waitValue){}

    I have over come my problem by creating a seperate script for each shortcut first and then running the scripts later. This does mean that there needs to be space for the temporary script files... but since each of those are under 1K each i do not suppose that it is much of an issue. It has however remakably increased performance by over 100 fold!
    here is the code if anyone is interested:
    import java.io.*;
    import java.util.*;
    class winVirtualFolder
         public static void main (String args[]) throws IOException
               File inFile = new File("directories.ini");
             FileReader fileReader = new FileReader(inFile);
             BufferedReader bufReader = new BufferedReader(fileReader);
             String str="";
                   String home="";
                   int count=0;
                   winVirtualFolder wVF=new winVirtualFolder();
             home= bufReader.readLine();
                   str=bufReader.readLine();
                   System.out.println("Home Directory: "+home);
                   Vector createdDirectories = new Vector();
                   File directory= new File(home);
                   String[] listing =directory.list();
                   for (int i=0;i<listing.length;i++)
                        if (wVF.isAlink(listing))
                             createdDirectories.add(listing[i].substring(0,listing[i].length()-4));
                             count++;
                   int startCount=count;
                   while (!str.equals("*END*"))
                        System.out.println("Creating shortcuts scripts of directories from "+str);
                        count=wVF.createScripts(str,home,createdDirectories,count);
                        str=bufReader.readLine();
                   System.out.print("Running Scripts");          
                   wVF.runScripts(startCount,count,home);
                   int dirCount=0;
                   File file;
                   while (dirCount<count-1)
                        dirCount=0;
                        String str1;
                        for (int i=0;i<createdDirectories.size();i++)
                             str1=(String) createdDirectories.get(i);
                             file = new File(home+""+str1+".lnk");
                             if (file.exists()) dirCount++;
                        System.out.print(".");
                        wVF.sleep(100);
                   System.out.println("Done!");
                   System.out.println("Deleting Scripts");
                   wVF.deleteScripts(startCount,count,home);
         int createScripts(String path,String home,Vector createdDirectories, int count) throws IOException
              File directory= new File(path);
              String[] listing =directory.list();
              File[] fileListing =directory.listFiles();
              String[] directories= new String[listing.length];
              for (int i=0;i<listing.length;i++)
                   if (fileListing[i].isDirectory())
                        int no=0;
                        String number="";
                        while(exists(listing[i]+""+number,createdDirectories))
                             no++;
                             number="-"+no;
                        createdDirectories.add(listing[i]+""+number);
                        File outFile = new File(home+"createShorcut"+count+".vbs");
              FileWriter fileWriter = new FileWriter(outFile);
                   BufferedWriter bufWriter = new BufferedWriter(fileWriter);
                        bufWriter.write("set WshShell = WScript.CreateObject(\"WScript.Shell\")\r\n");
                        bufWriter.write("set oShellLink = WshShell.CreateShortcut(\""+home+""+listing[i]+""+number+".lnk\")\r\n");
                        bufWriter.write("oShellLink.TargetPath = \""+path+""+listing[i]+"\\\"\r\n");
                        bufWriter.write("oShellLink.Description = \""+listing[i]+"\\\"\r\n");
                        bufWriter.write("oShellLink.Save\r\n");
              bufWriter.close();
                        count++;
              return count;
         void runScripts(int startCount,int count,String home) throws IOException
              for (int i=startCount;i<count;i++)
                   Runtime.getRuntime().exec("c:\\winnt\\system32\\wscript.exe \""+home+"createShorcut"+i+".vbs\"");
         void deleteScripts(int startCount,int count,String home) throws IOException
              for (int i=startCount;i<count;i++)
                   File outFile = new File(home+"createShorcut"+i+".vbs");
                   outFile.delete();
         void sleep (long time)
              long waitValue=System.currentTimeMillis()+time;
              while (System.currentTimeMillis()<waitValue){}
         boolean exists(String str,Vector createdDirectories)
              for (int i=0;i<createdDirectories.size();i++)
                   if (str.equals((String) createdDirectories.get(i))) return true;
              return false;
         boolean isAlink(String str)
              if (str.endsWith(".lnk"))
                   return true;
              return false;

  • Could not render the database - File is already open in another application - Fireworks unusable

    I'm using CC for mac and when trying to export an image in Fireworks I get this message popping up…
    It's constantly happening and even if I click ok or press the escape button I get a repeatedly blank version of the popup and I'm unable to export the image. This is rendering Fireworks unusable and along with Dreamweaver it's the application I use pretty much all the time so is a considerable annoyance.
    Can anyone help get this resolved please?

    I appear to have found the cause by chance. I was running AVG Anti-virus software but uninstalled that and hey presto Fireworks appears to be back to normal.

  • How to upload a text file from a shared folder and provide an o/p

    how to upload a text file from a shared folder and provide an o/p  containing the details in each order in the text file

    Hi,
    Use <b>GUI_UPLOAD</b> to upload a text file from a shared folder.
    Use <b>GUI_DOWNLOAD</b> to download data in a file on the presentation server or use <b>OPEN DATASET, TRANSFER</b> and <b>CLOSE DATASET</b> statements to download data to the application server.
    Now, I hope the code for data fetching, if required, is already present in the report.
    Reward points if the answer is helpful.
    Regards,
    Mukul

  • "File file path:to:file is already open" how do i close it?

    I am trying to write a script that pops up a dialog box, asks for text and saves this to a .csv and a .txt This is so i can quickly record what i am doing and the times i am doing it, makes quick notes and various things like that. However it is failing with the message "File file path:to:file is already open" so how do i close the file or get around this. Cheers
    Script Below
    tell me to activate
    display dialog "Enter the log message:" default answer "" buttons {"Cancel", "Ok"} default button "Ok"
    copy the result as list to {the log_message, the button_pressed}
    if the button_pressed is not "Cancel" then
    set curTime to (do shell script "date \"+%H:%M:%S\"")
    set curDate to (do shell script "date \"+%Y%m%d\"")
    set new_foldername to curDate
    set this_folder to (path to current user folder) as text
    set fPath2 to this_folder & "Documents:Logs:Date:" as alias
    --set this_folder to "Macintosh HD:Users:username:" as alias
    tell application "Finder"
    if not (exists folder new_foldername of fPath2) then
    make new folder at fPath2 with properties {name:new_foldername}
    end if
    end tell
    set fPath to (path to current user folder as Unicode text) & "Documents:Logs:Date:" & curDate & ":"
    set fName to curDate & ".csv"
    set myFile to open for access file ((fPath as string) & fName) with write permission
    write curTime & "," & log_message & return to myFile starting at eof
    close access myFile
    set fName2 to curDate & ".txt"
    set myFile to open for access file ((fPath as string) & fName2) with write permission
    write curTime & " " & log_message & return to myFile starting at eof
    close access myFile
    end if

    Hi Richard,
    Run this in the script editor:
    set f to choose file
    close access f
    Navigate to the file you left open. Probably there was an error and the file was left open because it never reached the 'close access' command.
    gl,

  • How to send a text file to a printer?

    Hi, I'm in dark on how to send a text file to a printer through Java Stored Procedure.
    Here are what I tried so far (OS: win 2000, Oracle: 817 or 9i2):
    1, Enable DOS command in Java Stored Proc. and try to send PRINT command there:
    public static String Run(String Command){
    try{
    Runtime.getRuntime().exec(Command);
    System.out.println("Command: " + Command);
    return("0");
    catch (Exception e){
    System.out.println("Error running command: " + Command +
    "\n" + e.getMessage());
    return(e.getMessage());
    public static void main(String args[]){
    if (args.length == 1)
    Run("print /D:\\\\enterprise\\john " + args[0]);
    else System.out.println("Usage: java OSCommand filename");
    PL/SQL wrapper:
    CREATE OR REPLACE FUNCTION OSCommand_Run(p1 IN VARCHAR2) RETURN VARCHAR2 AUTHID CURRENT_USER AS LANGUAGE JAVA NAME 'OSCommand.Run(java.lang.String) return java.lang.String';
    SQL command:
    //print /D:\\machine\printer test.txt
    I loaded the Java Stored Procedure into SYSDBS account, it failed silently, even though piece of code works fine in external JVM.
    2, Use filePrinter:
    public static String print(String printString) {
    try{
    String printerUNC = "\\\\machine\\printer";
    FileWriter fw = new FileWriter(printerUNC);
    PrintWriter pw = new PrintWriter(fw);
    pw.println(printString);
    fw.close();
    return "OK";
    }catch(Exception e){
    e.printStackTrace();
    return "Exception: " + e.getMessage();
    public static void main(String[] args) {
    try{
    String printerUNC = "\\\\machine\\printer";
    String printString = "Hello World";
    FileWriter fw = new FileWriter(printerUNC);
    PrintWriter pw = new PrintWriter(fw);
    pw.println(printString);
    fw.close();
    }catch(Exception e){e.printStackTrace();}
    I loaded it into SYSDBS too, and tried with this:
    SQL> select MY_PRINT.PRINT('HELLO from Oracle') from dual;
    MY_PRINT.PRINT('HELLOFROMORACLE')
    Exception: No such file or directory
    SQL> show user
    USER is "SYS"
    It works in external JVM too.
    What's wrong with this?
    Thanks for any help in advance,
    Charles

    Avi:
    Thanks for your response!
    I put the java code in SYS, 'cause I assume that account has max privilege. If the test is successful, I will move that to some user schema and then to deal with those privilege settings... But I'm unlucky.
    I checked Ask Tom, this is what I got from http://asktom.oracle.com/pls/ask/f?p=4950:8:1619723::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:38012348052,%7Bprinter%7D:
    ... Print file from PL/SQL ...
    If you are using Oracle8i, release 8.1 -- much can be done with Java. java
    would be able to print directly from the server.
    Looks like using Java to print out file is better than PL/SQL. But there's no more hint there! And, no new question can be asked there today either...
    I'm wondering whether we can create a socket to a printer and send the characters there directly... Anyone has experience on this?
    Thanks for all the help in advance,
    Charles

  • How to read a text file through pl/sql

    How to read a text file through pl/sql

    pl/sql runs inside the database. so your file also should be on the database server file system for you to be able to read.
    check out UTL_FILE package. This is the database package to read/write files on the database server.

  • How to check Whether the File is in Progress or used by some other resource

    Hi All,
    I am retrieving a file from the FTP server using Apache commons FTP.
    I need to check whether the file is fully retrieved or in progress.
    for now i can able to use the file which is partially retrieved. it is not throwing any file sharing exception or i am unable to find whether it is in progress.
    How to check whether the file is in progress ? or The file is accessed by some other resource ?
    Pls Help me.
    Thanks,
    J.Kathir

    Hi Vamsi,
    Explicitly such kind of requirement has not been catered and i dont think you would face a problem because any application that is writing to a file will open the file in the read only mode to any other simultaneous applications so i think your concerns although valid are already taken care off .
    In the remote case you still face a problem then as a work around. Tell the FTP administrator to set the property to maximum connections that can be made to ftp as one. I wonder if you have heard of the concept of FTP handle , basically the above workaround is based on that concept itself. This way only one application will be able to write.
    The file adapter will wait for its turn and then write the files.
    Regards
    joel
    Edited by: joel trinidade on Jun 26, 2009 11:06 AM

  • How can I sync text files into iPhone?

    How can I sync text files into iPhone? like doc. txt. for reading or editing

    The native iPhone OS doesn't allow that. I think there are several solutions to this, some of which may be against the AT&T or Apple rules. One legitimate solution is The Missing Sync for iPhone by mark/space (http://www.markspace.com).
    Before I had an iPhone, I owned a copy of The Missing Sync for Windows Mobile. It was a pretty decent app. In my opinion, though, their app for the iPhone is NOT worth the price ($40 new, $25 for a cross-grade).
    Also, check the App Store (if you have 2.0 software)--there may be an app that does this, probably for a lot less $.

  • How to convert a text file in lower case to upper case?

    I've a beginner in java world and I just come through the tutorial in http://java.sun.com/docs/books/tutorial/essential/io/filestreams.html showing how to copy a text file:
    import java.io.*;
    public class Copy {
    public static void main(String[] args) throws IOException {
         File inputFile = new File("farrago.txt");
         File outputFile = new File("outagain.txt");
    FileReader in = new FileReader(inputFile);
    FileWriter out = new FileWriter(outputFile);
    int c;
    while ((c = in.read()) != -1)
    out.write(c);
    in.close();
    out.close();
    And I would like to ask how to covert all lower case letters in input file to upper case letter in output file at the same time of copying.
    I guess it'll be using Character.toUpperCase(c), but I don't know how to do it actually.
    Any help would be much appreciated.

    Hope this helps
    import java.io.*;
    public class Copy {
    public static void main(String[] args) throws IOException {
    File inputFile = new File("farrago.txt");
    File outputFile = new File("outagain.txt");
    FileReader in = new FileReader(inputFile);
    FileWriter out = new FileWriter(outputFile);
    BufferedReader buff = new BufferedReader(in);
    String c;
    while ((c = buff.readLine()) != null)
    out.write(c.toUpperCase());
    in.close();
    out.close();
    }

  • How to read several text files at a time

    Dear all
          Read and write one text file is not a problem, but  what confusies me is how to read several text files at one time, in the meanwhile,
    is it possible to display the name of the text file?
    For example, assuming I want to load file" cha 1, cha 2 , cha 3, " at one time and show their names, how to hadle with it
    I have reviewed some files and it is not helpful

    Either with a 'for' loop like in the lib you have attached, or like this attached VI
    that's it
    Message Edited by devchander on 05-30-2006 05:11 AM
    Attachments:
    MULTIPLE READ.vi ‏44 KB

  • How to zip a text file and send as email attachment in SAP version 4.6c?

    Hi Guru,
    How to zip a text file in SAP version 4.6c which doesn't have class CL_ABAP_ZIP?
    Please help.
    Thanks & Regards,
    Ari

    Hi,
    Try this link
    [http://sap.ittoolbox.com/groups/technical-functional/sap-dev/sapr3dev-zip-file-from-sap-1707099?cv=expanded]
    Cheers,
    Surinder

Maybe you are looking for

  • Dissapeared videos & Mp3 files

    Today dissapeared videos & Mp3 files in Video and Music App, files are available only via File Commander and Downloads, - no music- no content available and the same is in Video App -no items, empty folders. I've been using Lolipop for 2 moths, not a

  • Displaying pdf files in Portal from application server.

    Hi, I have a requirement where i will give a link on the portal for Provident Fund related data. When the user clicks on the link, i have to retrieve his pdf file from the folder stored on the application server and display it in portal. Could you pl

  • Does executeBatch cause ResultSet to be closed?

    The JDBC API Tutorial and Reference, Second Edition, states that the following method calls cause the calling statement object's current ResultSet to be close if open - execute - executeUpdate - executeQuery However, it does not include executeBatch.

  • "Business Package for DMS Connector for KM" not available!?

    Hello Group, i tried to download and install the above mentioned PLM-Package. Unfortunately when i tried to download it from the portal-content-portfolio, after the redirection to the servicemarketplace says "no data available". Additionaly the docum

  • How to dislpay image in frame???

    I tried displaying image in a lable But it shows only a part of the image. Is there any function to resize a jpg file and display?