How to open directory in run time using java

Hi All
i hava problem for open a directory in run time in java.please help me with code.

Please elaborate what you mean by opening a directory. You can at all times access directory content via the File class.
File myDir=new File(<pathToDir>);
File[] directoryContent=myDir.listFiles();

Similar Messages

  • How create bath file in run time in java

    Hi all
    i run one bath file by using process class but i create bath file in run time in java .please help me with code.

    Dynamically Writing a batch file in Java is exactly the same as writing to a simple text file.... you just give it the file extension ".bat".
    If you can't write to a simple text file yet, you should probably buy a Java book and start working through it.
    regards,
    Owen

  • How to get server date and time using java code

    Hi,
    I'm new to java. I have one doubt about getting date and time of the server. can anyone give some sample code to get that.
    thanks in regards
    Gopi.

    you need 2 things
    1. something on the application server which exposes the servers time/date
    2. something on the client which makes use of your time service
    for instance, you could write a ServerTimeServlet that clients can call to get the time according to the server. or, if you've got a database in the server, often database software will provide a Time procedure or similar that does this, so you can use a simple SQL query to get the latest time

  • How to open a stored text file using java???

    Respected Sir / Madam
    I have a JList containing absolute path of files stored in my operating system in String format....I have added a ListSelectionListener...Now when i select an absolute path in the JList, the file should open ....I don't know how to do that....Hope you got my problem....Can any one pls help me out???
    Thank you[                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    thats ok buddy! best of luck
    U need to import
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    public void valueChanged(ListSelectionEvent e)
    if (!e.getValueIsAdjusting()) {
            String fileName=
              optionList.getSelectedValue().toString();
    final JFrame dialog = new JFrame(fileName);
              JEditorPane viewer = new JEditorPane();
              viewer.setEditable(false);
              JScrollPane jsp = new JScrollPane(viewer);
              try {
                   viewer.setPage("file:/" + fileName);
              } catch (Exception e) {
                   viewer.setText("Error opening " + fileName + ": " + e);
              dialog.getContentPane().add(jsp, BorderLayout.CENTER);
            JButton closeButton = new JButton("Close");
            closeButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    dialog.setVisible(false);
                    dialog.dispose();
              dialog.getContentPane().add(closeButton, BorderLayout.SOUTH);
              dialog.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
              //dialog.pack();
              dialog.setSize(600, 600);
              dialog.show();
    }

  • Open a file dialog box using java

    Duncan & Frank or anyone
    Can you please tell, or give me a link, which explains how to open a file dialog box using java, and not webutil.
    I'm trying to read a file on the desktop and update a database table.
    Thanks

    See Open File Dialog on the WEB... If you can get me the full version numbers I can tell you your supported position.
    Regards
    Grant

  • I accidentally quit my CC on my Macbook pro and now the cloud icon is grayed out and every time I hover over it with the mouse I get the spinning beach ball of death on the icon. I have no idea how to open it because when I use spotlight search to open it

    I accidentally quit my CC on my Macbook pro and now the cloud icon is grayed out and every time I hover over it with the mouse I get the spinning beach ball of death on the icon. I have no idea how to open it because when I use spotlight search to open it it gives me a message saying "Creative Cloud is not open anymore" help!

    Since you didn't include any pertinent info such as the Mac model and OS version you are running, here is some general information:
    Mac OS X: Gray screen appears during startup
    Depending on which OS yours came with originally - and which OS you are now running - you would either need your original install disks - you can call Apple for replacements by giving them your serial number. Or you may be able to reinstall the OS by using recovery (again, depends on which model/which OS).

  • In ABAP How to locate an Input file  from a Directory during run time

    I'm loading data from a flat file(text file) into SAP thru BDC programs. All my input files are present in Application server.How to locate an Input file in a directory during run time to process BDC programs programmatically. Are there any in-built functions?Provided me some sample code or any method of doing the same.

    Hello Murali,
    you should ask this question in the ABAP forum.
    Regards
    Gregor

  • How can I test the running time of a method?

    c.What is the running time of your method smallest, as a function of n, the number of elements in the list? Use big-Oh notation.
    I quoated from a java problem..
    Anyone can tell me how I can test the running time? Thanks ! :D

    it depends on what is in the method. For example a for loop executed n times would have a O(n). A double for loop (each loopp run n times) will have O(n^2). Do this: determine how many times each loop in the method is run. This is the first term in your runtime equation. Do this for all other loops in the method and add them all together. Most other statements that are not iterative should have a constant runtime so O(1). For conditional statements, the runtime depends on the most time consuming portion of the statement. Once all these are added together, take the O(equation) which should just leave the biggest term. i.e. O(5n^2+3n+8) = O(n^2). Hope this helps.
    note: this does not apply to recursive methods

  • How to open .drw or .prt file using swing?

    Hi Everyone,
    I am new to java programming n I m facing a problem in swing.I want to open a perticular drawing file using Java program but the condition is,it should open in the same window.Now,I have managed to open normal txt files n .doc files in the same window using JFileChooser and IO programming.But I dont know what it takes to open a .prt or a .drw file using the same program.
    Can you guys plz help me out in this?I think,it is not compatible to open such files...but how to make it compatible then?
    I m posting the code here...plz check it n help me out as soon as possible...Thank you very much......
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    public class FileChooseApp1 extends JFrame
    implements ActionListener
    JMenuItem fMenuOpen = null;
    JTextArea fTextArea;
    File fFile = new File ("default.java");
    FileChooseApp1 (String title) {
    super (title);
    Container cp = getContentPane ();
    // Create a user interface.
    cp.setLayout ( new BorderLayout () );
    fTextArea = new JTextArea ("");
    cp.add ( fTextArea, "Center");
    JMenu m = new JMenu ("File");
    m.add (fMenuOpen = makeMenuItem ("Open"));
    JMenuBar mb = new JMenuBar ();
    mb.add (m);
    setJMenuBar (mb);
    setSize (400,400);
    public void actionPerformed ( ActionEvent e ){
         boolean status = false;
         String command = e.getActionCommand ();
         if (command.equals ("Open")) {
         // Open a file
              status = openFile ();
         private JMenuItem makeMenuItem (String name) {
         JMenuItem m = new JMenuItem (name);
         m.addActionListener (this);
         return m;
         boolean openFile () {
         JFileChooser fc = new JFileChooser ();
         fc.setDialogTitle ("Open File");
         // Choose only files, not directories
         fc.setFileSelectionMode ( JFileChooser.FILES_ONLY);
         // Start in current directory
         fc.setCurrentDirectory (new File ("."));
         // Set filter for Java source files.
         // fc.setFileFilter (fJavaFilter);
         // Now open chooser
         int result = fc.showOpenDialog (this);
         if (result == JFileChooser.CANCEL_OPTION) {
         return true;
         } else if (result == JFileChooser.APPROVE_OPTION) {
         fFile = fc.getSelectedFile ();
         // Invoke the readFile method in this class
         String file_string = readFile (fFile);
         if (file_string != null)
         fTextArea.setText (file_string);
         else
         return false;
         } else {
         return false;
         return true;
         } // openFile
         public String readFile (File file) {
         StringBuffer fileBuffer;
         String fileString=null;
         String line;
         try {
         FileReader in = new FileReader (file);
         BufferedReader dis = new BufferedReader (in);
         fileBuffer = new StringBuffer () ;
         while ((line = dis.readLine ()) != null) {
         fileBuffer.append (line + "\n");
         in.close ();
         fileString = fileBuffer.toString ();
         catch (IOException e ) {
         return null;
         return fileString;
         } // readFile
         public static void main (String [] args) {
         // Can pass frame title in command line arguments
         String title="Frame Test";
         if (args.length != 0) title = args[0];
         FileChooseApp1 f = new FileChooseApp1 (title);
         f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
         f.setVisible (true);
         } // main
         } 

    well....the issue is,by the above mentioned code,I m able to open all text files like .txt or .doc....but I want to open a file having an extension .eprt or .easm.....these are all drawing related files....how to do that?
    what exactly happens when a text file is opened in java...do I need to register these drawing related files somewhere?if yes,wher should I register them?
    Thanks a lot.....

  • How to avoid the run time error  "java.lang.OutOfMemoryError"

    hi
    i have written a code to read a txt file ,i used FileReader to read a file . the code is working well for small txt files. but when i tried to read a large file(greater than 2MB), a run time error called "java.lang.OutofMemoryError" appeared .
    plz suggest the methods to read txt files of large capacity(greater than 25MB) .if possible give an example.

    thanks for ur replies
    i am new to java programming .i am a student persuing B.Tech final semester .i got struck in my project while reading a large txt file(greater than 3MB) . i am now giving a part of code that i had used in my project .it working fine with the txt files less than 3MB ,but when i am treing to read a file greater than 3MB , it is displaying a run time error "java.lang.outofmemoryerror"
    i have tried using "java -Xmx" ,it is working , but is there any better option ??
    here is the part of code:
       FileReader fin;
        al=new ArrayList();
         try
              fin=new FileReader(filename);
         catch(FileNotFoundException e)
           System.out.println("File not foumn");
         return;
    while((i=fin.read())!=-1)
           al.add(new Character((char)i));
         fin.close(); 
         Object obj[]=al.toArray();plz help me
    --santosh                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Open Folder by double click using java.awt

    Hello Guys,
    I have a problem. I m listing directory in List(java.awt). When i single click on directory it will open. But how i can double click on that directory then and then it will open otherwise not. By using JAVA.AWT.

    According to the documentation for java.awt.List "When an item is selected or
    deselected by the user, AWT sends an instance of ItemEvent to the list. When
    the user double-clicks on an item in a scrolling list, AWT sends an instance of
    ActionEvent to the list following the item event. AWT also generates an action
    event when the user presses the return key while an item in the list is selected."
    If your directories are "opening" (whatever that means) in response to a single
    click, that it because of how you have written your code. Change it so that action
    events rather than item events cause the opening to happen.

  • Running files using java

    Please help, how can i run files using java.
    Files such as installers, batch files, or exe files....
    thanx

    Dear
    To run an EXE or COM or (other types of files other than BAT) use
    Runtime.exec("program-file-name.exe");
    while for running BAT files, always use this syntax
    Runtime.exec("bat-filenane", null, "bat-file-directory");
    Thats all.
    If your directory name or filename contains spaces, then surround the directoryname + filename within double quotes.
    Regard
    Dharmendra!
    Software Engineer(Java/J2EE)

  • How to get the current GMT time in java

    Hi,
    How to get the current GMT time in java
    Thanks

    System.getCurrentTimeMillis() or new Date().
    [url http://www.javaworld.com/jw-12-2000/jw-1229-dates.html]Calculating Java dates: Take the time to learn how to create and use dates
    [url http://www.javaalmanac.com/egs/java.text/FormatDate.html]Formatting a Date Using a Custom Format

  • How to extract .sit files(in MAC)  using java program

    Hi,
    please help me , i want to simple program for
    " how to extract .sit files(in MAC) using java program"
    that sit files same as zip files in windows..[                                                                                                                                                                                                                                                                                                                                   

    Thanks for reply...
    but i search in the google about this topic...there is no results will appear..
    the problem is "i have to run program in the MacOS like extract all the
    .sit(StuffIt) extension files. These sit files same as zip files in the windows... we have one tool called StuffIt Expander but it is 3rd party tool. but here requirement is i have to write my own program to extract all the files same as zip file program...
    please do the needful..i am waiting for ur reply,,,

  • Opening a template indd file using java API

    How do I open a template indd file using java API and use it for laying out graphics and text ?
    Thanks in advance

    Sample code:
    VariableType vtDocument = myApp.open(VariableTypeUtils.createFile("c:\\myfile.indd"));
    myDocument = DocumentHelper.narrow(vtDocument.asObject());
    Thanks
    -arun

Maybe you are looking for

  • TOC in merged slave project does not find the page, but Search does

    I have a slave CHM file, where the TOC is non-binary. This is merged into a master project, which also has a TOC that is non-binary. When I view the merged project, just from RoboHelp, the TOC includes the slave embedded properly in the master TOC. H

  • Photo Place Box

    How do I turn off or get rid of that %$$#$@! little "i" in the corner of the thumbnail? Half the time when I try to open the photo I hit it and open the "Photo Place" box instead, and have to waste time closing it.

  • Forwarding events from my menubar class to main class

    I'm brand new to swing. I'm trying write an app, and wanted to encapsulate my JToolBar and JMenuBar items, so I made classes to handle each of them. Then from my "main" class I could just call a function and voila. However the one obvious problem is

  • Assigning javascript variables to java variables in JSP

    Does anyone know if it possible to assign a javascript value to a java variable in a javascript function? I want to be able to use the javascript value in a PreparedStatement call, but I can't assign the value of the javascript variable to a java var

  • Are there any problems with a "required Extended Protection" / "Always On" / "Livelink Server" combination?

    Hello, we have a Livelink  Server database running with two replicas on two nodes as Always On Group, both instances running extended protection in "allowed" mode. Our company security policy demands setting the extended protection to "required". Are