How to close external files opened via java via java itself?

hi,
I am using jdk1.6 so I've used the Desktop Class to run the .bat file for some purposes via java with the open(File f) method. Now, what I want is to close those opened .bat files but had no idea so I would appriciate any help.
thank you,
Jay

Okay, now I've used the ProcessBuilder class for that
approach. Now I can find the destroy() method in the
Process class but it didn't help me. Here's how I
tried:
public class Main extends JFrame implements
ActionListener
Command com;
public Main()
super();
com=new Command(1,this); // this class
class implements ActionListener and handles the
actions happening in the Main class.
a_button.addActionListener(com);
/* from the Command class the ProcessBuilder is
der is started returning the instance proc of the
class Process.*/
public void windowClosing(WindowEvent evt)
com.proc.destryo(); //<------ does the API really have a typo in it?
System.exit(0);
public void window.....(WindowEvent evt){}....
}regards,
Jay

Similar Messages

  • How to call external files from java?

    How to call external files in java. For example how to call a *.pdf file to open in its default editor(say Acrobat), or a *.html file to open in the default browser or a *.txt file in a notepad etc..,
    In my program i have *.chm (Compiled Windows HTML Help) help file. how to open it in its default editor it?

    Jayarathina_Madharasan wrote:
    no one answered my questionHi what wrong did i do...basically insulted all the volunteers here who took the time to consider your question and try to offer you help. Other than that, you did nothing wrong.
    From JavaRanch :
    And even if an answer doesn't solve your problem, even if it should totally miss the point - the best thing to do to motivate others to continue trying to help you is showing respect and gratitude for the investment of time that was put into dealing with your issue.
    Edited by: Encephalopathic on Apr 14, 2008 10:01 AM

  • I have an iMac. , mid 2007.  Frequently, when I take an action, the little color wheel starts spinning and goes on for quite awhile.  Save a file, close a file, open a file, open a window, it's all random.  Somtimes it stalls, sometimes it doesn't.  Why?

    I have an iMac. , mid 2007.  Frequently, when I take an action, the little color wheel starts spinning and goes on for quite awhile.  Save a file, close a file, open a file, open a window, it's all random.  Somtimes it stalls, sometimes it doesn't.  Sometimes long, sometims short.  Why is this happening?

    Consider adding more memory. Be sure you have adequate free space on the hard drive - 15 GBs or 10% of the drive's capacity, whichever is greater. Do not run too many applications concurrently. Visit The XLab FAQs and read the FAQ on resolving the SBBOD.
    Do some maintenance:
    Repair the Hard Drive and Permissions
    Boot from your Leopard Installer disc. After the installer loads select your language and click on the Continue button. When the menu bar appears select Disk Utility from the Utilities menu. After DU loads select your hard drive entry (mfgr.'s ID and drive size) from the the left side list.  In the DU status area you will see an entry for the S.M.A.R.T. status of the hard drive.  If it does not say "Verified" then the hard drive is failing or failed. (SMART status is not reported on external Firewire or USB drives.) If the drive is "Verified" then select your OS X volume from the list on the left (sub-entry below the drive entry,) click on the First Aid tab, then click on the Repair Disk button. If DU reports any errors that have been fixed, then re-run Repair Disk until no errors are reported. If no errors are reported click on the Repair Permissions button. Wait until the operation completes, then quit DU and return to the installer.
    If DU reports errors it cannot fix, then you will need Disk Warrior and/or Tech Tool Pro to repair the drive. If you don't have either of them or if neither of them can fix the drive, then you will need to reformat the drive and reinstall OS X.
    Kappy's Personal Suggestions for OS X Maintenance
    For disk repairs use Disk Utility.  For situations DU cannot handle the best third-party utilities are: Disk Warrior;  DW only fixes problems with the disk directory, but most disk problems are caused by directory corruption; Disk Warrior 4.x is now Intel Mac compatible. Drive Genius provides additional tools not found in Disk Warrior.  Versions 1.5.1 and later are Intel Mac compatible.
    OS X performs certain maintenance functions that are scheduled to occur on a daily, weekly, or monthly period. The maintenance scripts run in the early AM only if the computer is turned on 24/7 (no sleep.) If this isn't the case, then an excellent solution is to download and install a shareware utility such as Macaroni, JAW PseudoAnacron, or Anacron that will automate the maintenance activity regardless of whether the computer is turned off or asleep.  Dependence upon third-party utilities to run the periodic maintenance scripts was significantly reduced since Tiger.  These utilities have limited or no functionality with Snow Leopard or Lion and should not be installed.
    OS X automatically defragments files less than 20 MBs in size, so unless you have a disk full of very large files there's little need for defragmenting the hard drive. As for virus protection there are few if any such animals affecting OS X. You can protect the computer easily using the freeware Open Source virus protection software ClamXAV. Personally I would avoid most commercial anti-virus software because of their potential for causing problems. For more about malware see Macintosh Virus Guide.
    I would also recommend downloading a utility such as TinkerTool System, OnyX 2.4.3, or Cocktail 5.1.1 that you can use for periodic maintenance such as removing old log files and archives, clearing caches, etc.
    For emergency repairs install the freeware utility Applejack.  If you cannot start up in OS X, you may be able to start in single-user mode from which you can run Applejack to do a whole set of repair and maintenance routines from the command line.  Note that AppleJack 1.5 is required for Leopard. AppleJack 1.6 is compatible with Snow Leopard. There is no confirmation that this version also works with Lion.
    When you install any new system software or updates be sure to repair the hard drive and permissions beforehand. I also recommend booting into safe mode before doing system software updates.
    Get an external Firewire drive at least equal in size to the internal hard drive and make (and maintain) a bootable clone/backup. You can make a bootable clone using the Restore option of Disk Utility. You can also make and maintain clones with good backup software. My personal recommendations are (order is not significant):
    Carbon Copy Cloner
    Data Backup
    Deja Vu
    SuperDuper!
    SyncTwoFolders
    Synk Pro
    Synk Standard
    Tri-Backup
    Visit The XLab FAQs and read the FAQs on maintenance, optimization, virus protection, and backup and restore.
    Additional suggestions will be found in Mac Maintenance Quick Assist.
    Referenced software can be found at CNet Downloads or MacUpdate.
    Be sure you have an adequate amount of RAM installed for the number of applications you run concurrently. Be sure you leave a minimum of 10% of the hard drive's capacity as free space.

  • How to Install .CAP file in the Java Card?

    Hi Friends..
    How to install *.CAP* file in the Java Card?..
    I've GPShell script as follows :
    mode_211
    enable_trace
    establish_context
    card_connect -readerNumber 2
    open_sc -security 1 -keyind 0 -keyver 0 -mac_key 404142434445464748494a4b4c4d4e4f -enc_key 404142434445464748494a4b4c4d4e4f
    install_for_load -pkgAID a00000006203010c01 -nvCodeLimit 500  -sdAID A000000003000000
    load -file HelloWorld.cap
    card_disconnect
    release_contextwith that script i can load HelloWorld.cap file successfully..
    Now, how to install the HelloWorld.cap file?..
    if i add script : load -file HelloWorld.cap i got this error :
    install -file HelloWorld.cap
    file name HelloWorld.cap
    Command --> 80E602001B09A00000006203010C0107A00000015100000006EF04C60201A80000
    Wrapped command --> 84E602002309A00000006203010C0107A00000015100000006EF04C60201
    A80030C859793049B85300
    Response <-- 6985
    install_for_load() returns 0x80206985 (6985: Command not allowed - Conditions of
    use not satisfied.)i ask this question because when i tried to select the applet through its AID, by this script :
    establish_context
    card_connect -readerNumber 2
    select -AID a00000006203010c0101i got this message error : select_application() returns 0x80216A82 (6A82: The application to be selected could not be found.)
    but there's exactly any that AID in my Java Card..
    here's is the list of AID from My Java Card :
    C:\GPShell-1.4.2>GPShell listgp211.txt
    mode_211
    enable_trace
    establish_context
    card_connect -readerNumber 3
    * reader name OMNIKEY CardMan 5x21-CL 0
    select -AID a000000003000000
    Command --> 00A4040008A000000003000000
    Wrapped command --> 00A4040008A000000003000000
    Response <-- 6F108408A000000003000000A5049F6501FF9000
    open_sc -security 1 -keyind 0 -keyver 0 -mac_key 404142434445464748494a4b4c4d4e4
    f -enc_key 404142434445464748494a4b4c4d4e4f // Open secure channel
    Command --> 80CA006600
    Wrapped command --> 80CA006600
    Response <-- 664C734A06072A864886FC6B01600C060A2A864886FC6B02020101630906072A864
    886FC6B03640B06092A864886FC6B040215650B06092B8510864864020102660C060A2B060104012
    A026E01029000
    Command --> 8050000008AAF7A87C6013BC0300
    Wrapped command --> 8050000008AAF7A87C6013BC0300
    Response <-- 0000715457173C2A8FC1FF0200937A55C288805D8F2A04CCD43FA7E69000
    Command --> 848201001023CA18742D36165ED992CFF2146C3D51
    Wrapped command --> 848201001023CA18742D36165ED992CFF2146C3D51
    Response <-- 9000
    get_status -element 10
    Command --> 80F21000024F0000
    Wrapped command --> 84F210000A4F004FF8BE1492F7275400
    Response <-- 0CF0544C00004D4F44554C415201000009A00000006203010C010100010AA000000
    06203010C01019000
    GP211_get_status() returned 2 items
    List of Ex. Load File (AID state Ex. Module AIDs)
    f0544c00004d4f44554c4152        1
    a00000006203010c01      1
            a00000006203010c0101
    card_disconnect
    release_contextPlease help me..
    And please correct me if i'm wrong,,
    Thanks in advance..

    Any suggestions for my question?..
    Please help me..
    Thanks in advance..

  • How to close and re-open the browser

    I have just downloaded a program and to fully install it it is requesting that I close the browser and re-open it. I don't know how to close and re-open the browser. Can you tell me how to close and re-open the browser? Thank you

    It is always best to use File > Exit<br />
    That will close all open windows, so if there are still other windows open then these won't close if you use the close X on the title bar.
    Also make sure that you do not have security software that is locking files in the Firefox program folder.

  • How to close external programs?

    Hi there,
    in vbs is a command "ExtProgram(ExtProgramName, ExtProgramArg)" to
    start external programs. But how to  close external programs when
    they finished its work? Is there a vbs-command for it? Is there a way
    when calling "cmd.exe" with a proper parameter?
    Martin Bohm

    Hello Martin!
    Yes, with the tool 'tasklist' in the same directory.
    The problem is that it is not easy to query from script. I tried it in the following script. Perhaps not perfect espacially because a command interpreter pop up every time you call the function.Option Explicit
    If IsDIAdemRunning() Then
    Call MsgBox( "At least one DIAdem is running!" )
    Else
    Call MsgBox( "No DIAdem at all!" )
    End If
    Function IsDIAdemRunning()
    Dim oWshShell
    Dim oExec
    ' Execute via Shell Object
    Set oWshShell = CreateObject("WScript.Shell")
    Set oExec = oWshShell.Exec( "C:\windows\system32\tasklist.exe /FI ""IMAGENAME eq DIAdem.exe""")
    ' wait until tasklist is finished
    Do While oExec.Status = 0
    Pause(1)
    Loop
    ' no Standard Output -> no DIAdem running
    IsDIAdemRunning = Len(oExec.StdOut.ReadAll) <> 0
    End Function
    A better solution might be possible via WMI.
    Matthias
    Matthias Alleweldt
    Project Engineer / Projektingenieur
    Twigeater?  

  • How to use .properties files in Webdynpro Java code?

    Hi all,
      I want to use a logon.properties file when I initial a JCO connection pool in my webdynpro DC (JCO.addClientPool()),but  I found when I deployed this DC to the server, it always giv e me an FileNotFoundException. So I donot know how to deploy a .properties file to the server and how to access this file in my Java code?
    Thans and Best regards
    Deyang

    Hi,
    1) put .properties file to your packege under src\packages folder (src\packages\com\sdn\properties\jco.properties)
    2) load property:
         final InputStream is = getClass().getClassLoader().getResourceAsStream("com/sdn/properties/jco.properties");
         final Properties properties = new Properties();
         try
              properties.load(is);
         catch(Exception e)
              wdComponentAPI.getMessageManager().reportException(new WDNonFatalException(e), false);
    Regatds Maxim R.

  • How to include external files in JSP

    hi,
    How to include external files like image or javascript in to jsp pages.
    I am using MVC frame work. So i have to use request dispatcher. While calling the pages trough dispatcher the external files are missing from the output. Also am using tomcat as server,web.xml(deployment descriptor ) is also configured.
    regards
    sree

    When you use the request dispatcher, the relative path for all your ressources becomes the relative path of your calling serlvet and not the JSP/servlet that you call. Make sure to use the full relative path such as:
    /PATH_TO_YOUR_DIRECTORY/myRessource.ext
    NOT
    SOME_DIRECTORY/myRessource.ext
    Jeff

  • External files opening behind the projector

    I have used 'baOpenFile' function to open some external files
    (pdf, pps etc). In most computers everything works great, but in
    some computers the file opens behind the projector (which is in
    full screen mode), and user doesn't see that the file has opened.
    To solve this problem I have used
    'baWindowToBack(baWinHandle())' to send the projector window back
    before the external file opens. It works, but it's ugly solution
    (especially if there's many windows open on desktop). Does anyone
    know why external files open behind the projector, and is there a
    better way to fix the problem than the one that I've used?

    Instead of sending the Director window to the back, it may be
    better to
    bring the new window to the front. That will bypass the issue
    of other
    windows appearing over the Director window.
    I do not know why this happens, and I have seen it in action
    many times
    myself. It is annoying, but easily worked around.

  • How to open external files in a Java stored procedure?

    Hi y'all,
    I'm trying to open an external text file from a Java stored procedure. The java sp has been successfully loaded, resolved, published, etc. in Oracle. I'm using the following statement to try to open the file (enclosed in a try/catch block):
    BufferedReader fileObj = new BufferedReader(new FileReader("fileName.txt"));
    I'm getting a file not found error. Where is Oracle looking (i.e., what directory)?
    Your help is greatly appreciated,
    Gary

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Gary Nool ([email protected]):
    Hi y'all,
    I'm trying to open an external text file from a Java stored procedure. The java sp has been successfully loaded, resolved, published, etc. in Oracle. I'm using the following statement to try to open the file (enclosed in a try/catch block):
    BufferedReader fileObj = new BufferedReader(new FileReader("fileName.txt"));
    I'm getting a file not found error. Where is Oracle looking (i.e., what directory)?
    Your help is greatly appreciated,
    Gary<HR></BLOCKQUOTE>
    Hi Gary,
    you must use a "database directory", e.g:
    SQL>create directory WORKING_DIR as '/home2/common/';
    SQL> select * from all_directories;
    OWNER DIRECTORY_NAME
    DIRECTORY_PATH
    SYS WORKING_DIR
    /home2/common/
    Gert

  • How to close all files that an Applescript has opened?

    I'm writing a script with multiple "open for access file ... with write permission" commands. It writes to various of them, making csv databases as it works its way through analyzing an xml file (generated by other software), then closes them all at the end.
    My problem is that, if the script crashes or I have to halt it before it gets to the "close" commands at the end, the files are left open. This causes an obvious error when next running the script after making adjustments.
    How can I ensure that those files are always closed? At present I'm doing it by quitting and re-starting Script Editor, which leaves me disoriented in the code.
    Is there a generic close command that I can insert at the start of the script, for example?

    Use this handler to open files.  It tries to open the file, and if it gets error -49 (file already open) it closes the file and reopens it.  It returns a file pointer to the open file, which you can use to refer to the file later.
    on openAFile(filePath, writable)
              try
                        set fp to open for access filePath write permission writable
              on error errstr number errNum
                        if errNum = -49 then
                                  close access filePath
                                  set fp to open for access filePath write permission writable
                        else
                                  display dialog errstr
                                  return false
                        end if
              end try
              return fp
    end openAFile
    set pointer to openAFile("/path/to/some/file", true)
    set fileContents to read pointer
    --close access pointer

  • File open in java

    I have created a small application to upload any file and save it in a temporary directory.
    Then display all the file names which are in that directory.here's my code ....
    MultipartRequest mr = null;
                   try {
                        mr = new MultipartRequest(req, ".");                              
                        BufferedReader br = new BufferedReader(new FileReader(fileName = (String)mr.getFilesystemName("importFile")));
                   } catch(Exception e) { System.out.println("Error uploading from file '"+fileName+"': "+e); e.printStackTrace();
                   } finally { new File(fileName).delete(); }
                   String dir = "C:\\asta-timesheet\\temp\\";
                   Vector fileVector = new Vector();
                   boolean result = false;
                   DataInputStream dis;
                   FileInputStream fin;
                   try {               
                        String fileContent = "";
                        Enumeration files = mr.getFileNames();
                        String name = (String)files.nextElement();
                        String filename = mr.getFilesystemName(name);
                        String type = mr.getContentType(name);
                        File f = mr.getFile(name);
                        FileReader fs = new FileReader(f);
                        BufferedReader in = new BufferedReader(fs);
                        String s, s2 = new String();
                        while((s = in.readLine())!= null) {
                        s2 += s + "\n";
                        fileContent = s2;     
                        in.close();                                                                 
                   File file = new File(dir, fileName);           
         // Create file if it does not exist
         boolean success = file.createNewFile();
         if (success) {              
                             InputStream inn = new FileInputStream(f);
                   OutputStream out = new FileOutputStream(file);
                   // Transfer bytes from in to out
                        byte[] buf = new byte[1024];
                        int len;
                   while ((len = inn.read(buf)) > 0) {
                   out.write(buf, 0, len);
                   inn.close();
                   out.close();
         } else {
         // File already exists     
         req.setAttribute("fileStatus", "exists");
              } catch(Exception e) { System.out.println("Error uploading from file '"+fileName+"': "+e); e.printStackTrace();}
                   File dirr = new File(dir);
              String[] children = dirr.list();
              if (children == null) {
              } else {
              for (int i=0; i<children.length; i++) {                    
              String filename = children;
              // The list of files can also be retrieved as File objects
              File[] files = dirr.listFiles();
              for (int i = 0; i < files.length; i++) {
                        File f = files[i];                                                                           
                   req.setAttribute("fileVector", files);                    
              return returnPage;
    I need help with opening up the listed files.i.e if its a word doc.i need it to be open on ms word.I have file types like excel,jpg,txt....Can someone pls explain or provide code for this.
    thx in advance.

    All you could use to detect the correct type would be the extension which might or might not be accurate. We'll assume for a moment that the extensions will be accurate. What you need to look into running native code. Follow the bouncing link.
    http://www.google.com/search?hl=en&q=Java+%2B+native+code&btnG=Google+Search
    Hope this helps,
    PS.
    One more thing, please use code tags when you're posting code, it makes it much easier to read.
    Message was edited by:
    puckstopper31

  • Close a file opened in windows XP

     Hi guys,
    I'm writing data in a text file and I saw if the file is already open in Windows XP the data are not written and I have no error message.
    So my question is how can I close the file in Windows with Labview ?
    And is there a way to check before closing it if the file is open by Windows ?
    I tried with "close file" and with "close file+.vi" but it's not working. 
    Thanks 

    remvu wrote:
    Thank you smercurio_fc for you reply, but I didn't succeed to close my file.
    If I understand it right  I should look on Microsoft side and not in a function in Labview ?
    Like to use the command with the cmd.exe to close it ?
    Yes, it is a command-line program made by Microsoft. The code that cheggers attached is basically how you would use it. As I noted, the utility is designed to track files opened by network users. To track files opened locally you need to run the command with the "/local ON" parameters. You only need to do this once, though a reboot is required. More information can be found on the Microsoft site.

  • How to make InDesign files open by default in CC, not CC 2014

    Now that I have 2 version of InDesign on my mac (10.8.5 - Mountain Lion), both CC and CC 2014, how can I make my .indd files open by default in CC instead of the new 2014 version?
    I've tried selecting a .indd file, opening the Info panel and changing the "Open with:" option to "Adobe InDesign CC.app 9.2.2.103". I then click Change All.. and confirming. However, this does not work. Double-clicking any .indd file still opens in the 2014 version and the Info panel for any .indd file still shows the 2014 version as the "Open with:" default.
    Any ideas?

    Here are three methods. The first two are free but don't give you exactly what you want. The third requires a third-party utility and works perfectly.
    (1) Right-click on a file and from the menu choose Open With... then choose the version of InDesign you want.
    (2) Create an alias for your InDesign versions and place them on your Desktop. Drag your InDesign file onto the alias of the version you want to open.
    (3) Purchase Soxy from Rorohiko:
    Soxy | Rorohiko Workflow Resources
    NOTE: Rorohiko says the version that supports InDesign CC 2014 is coming soon, they're waiting to test the new version before they release it.

  • How to specify a file path in java code to run on Unix machine?

    Hi
    I have a problem when running my project Swing on Unix machine.
    In my code, the user will press a button and then the program will look for the file "ReadMe" in the folder "Documentation" , and reads the content of this file. My code is "Documentation\\ReadMe" and it works well on PC. (The folder "Documentation" is in the same directory with my Java code).
    But when I try on Unix, the program can not read the file. It can only read the file "ReadMe" if I take this file and put it in the same directory with my Java code ( this means not through another folder). So how can we make it read the file in a folder ? It seems that "Documentation\\ReadMe" does not work in Unix, or the symbol "\\" does not work.
    I would be thankful if anybody can help me with this.
    Thank you very much

    You really shouldn't use any path method, as neither are very consistant or platform independent. The JVM provides a way to grab resources from the classpath. These resources can be any data at all, in fact, it's how java itself locates classes. Here's an example how you would do this in a non-static method.
    public URL getReadMe() {
      // In this context the forward slash is universal
      String docDirectory = "Documentation/"
      // We have to use the classloader to grab the resource
      ClassLoader cl = this.getClass().getClassLoader();
      // Next we get the resource 
      URL readMeURL = cl.getResource(docDirectory + "ReadMe");
      return readMeURL;
    }The URL can be used in whatever way you need to get the information out of the resource. If it was an image you might use the "Toolkit" to make an image object out of it. The great thing about this method is it will work even if your loading the program out of a Jar file. The resource paths start at the top of the classpath, just like classes.

Maybe you are looking for

  • Wrong combination of Plant and Co code at the time of PO creation

    Dear all, At the time of creating PO when I am entering Plant and Company code system is not giving any error message if I am entering other Co code , i.e. Co code which is not assigned to the plant. I want an error message in case of maintaining wro

  • Problem with update for Windows 7 64 bit

    I downloaded and updated to the newest version of iTunes, but when I restarted, as requested, my internet wouldn't work anymore. Not just when iTunes was open mind you....it wouldn't work AT ALL!! Up until the update iTunes ran fine, the internet was

  • Unable to view project in full screen mode.

    I'm working on three different imovie projects, and they are all in my project library. For two of the three projects I have no problems viewing them on the full screen mode, but the one that I'm currently working on won't play full screen when selec

  • Parallel approval question of the workflow process.

    Hello Expert, I have the following business process scenario which will be realized by new BPMN. My qusestion is how to do with it on BPMN? I have one human activity in one step. The condition to pass this step is that all the potential owners of thi

  • Question regarding magsafe connector

    i would just like to ask if the magsafe connector which is a magnet accidentally touched the adapter for like 30 seconds? would it damage the adapter?