How use java.io.File ?

import java.io.File;
public class test {
     void     help( String[] info ) {
          for ( int x = 0; x < info.length; x++ )
               System.out.println( info[x] );
     public static void main( String[] args ) {
          test t = new test();
          t.help( args );
          File f = new File("args[0]");
          t.help( f.list() );
}The File.list() return "String[]", but it no same for "String[] agrs". How to use File.list() ?

Try doing File f = new File(args[0]);

Similar Messages

  • How use the permision file

    I HAVE THE PERMISION FILE "myfile.police"
    IN C:\INETPUB\WWWROOT
    grant codeBase "http://localhost/directory/" {
    permission java.security.AllPermission;
    AND THE APPLET CODE
    public void init()
    //�����how use here the file "myfile.police" ???????
    //��� who its the code ????
    Thanks in advance.

    Hope you have fixed it, but anyway look under rmi.

  • Trying to write data to a text file using java.io.File

    I am trying to create a text file and write data to it by using java.io.File and . I am using JDeveloper 10.1.3.2.0. When I try run the program I get a java.lang.NullPointerException error. Here is the snippet of code that I believe is calling the class that's causing the problem:
    String fpath = "/test.html";
    FileOutputStream out = new FileOutputStream(fpath);
    PrintStream pout = new PrintStream(out);
    Do I need to add additional locations for source files or am I doing something wrong? Any suggestions would be appreciated.
    Thank you.

    Hi dhartle,
    May be that can help:
    * Class assuming handling logs and connections to the Oracle database
    * @author Fabre tristan
    * @version 1.0 03/12/07
    public class Log {
        private String fileName;
         * Constructor for the log
        public Log(String name) {
            fileName = name;
         * Write a new line into a log from the line passed as parameter and the system date
         * @param   line    The line to write into the log
        public void lineWriter(String line) {
            try {
                FileWriter f = new FileWriter(fileName, true);
                BufferedWriter bf = new BufferedWriter(f);
                Calendar c = Calendar.getInstance();
                Date now = c.getTime();
                String dateLog =
                    DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM,
                                                   Locale.FRANCE).format(now);
                bf.write("[" + dateLog + "] :" + line);
                bf.newLine();
                bf.close();
            } catch (IOException e) {
                System.out.println(e.getMessage());
         * Write a new line into a log from the line passed as parameter,
         * an header and the system date
         * @param   header  The header to write into the log
         * @param   info    The line to write into the log
        public void lineWriter(String header, String info) {
            lineWriter(header + " > " + info);
         * Write a new long number as line into a log from the line 
         * passed as parameter, an header and the system date
         * @param   header  The header to write into the log
         * @param   info    The line to write into the log
        public void lineWriter(String header, Long info) {
            lineWriter(header + " > " + info);
         * Enable to create folders needed to correspond with the path proposed
         * @param   location    The path into which writing the log
         * @param   name        The name for the new log
         * @return  Log         Return a new log corresponding to the proposed location
        public static Log myLogCreation(String location, String name) {
            boolean exists = (new File(location)).exists();
            if (!exists) {
                (new File(location)).mkdirs();
            Log myLog = new Log(location + name);
            return myLog;
         * Enable to create the connection to the DB
         * @return  Connection  Return a new connection to the Oracle database
        public static Connection oracleConnectionCreation() throws Exception {
            // Register the Oracle JDBC driver
            DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
            //connecting to the DB
            Connection conn =
                DriverManager.getConnection("jdbc:oracle:thin:@myComputerIP:1521:myDB","user", "password");
            return conn;
         * This main is used for testing purposes
        public static void main(String[] args) {
            Log myLog =
                Log.myLogCreation("c:/Migration Logs/", "Test_LinksToMethod.log");
            String directory = "E:\\Blob\\Enalapril_LC-MS%MS_MS%MS_Solid Phase Extraction_Plasma_Enalaprilat_ERROR_BLOB_test";
            myLog.lineWriter(directory);
            System.out.println(directory);
    [pre]
    This class contained some other functions i've deleted, but i think it still works.
    That enables to create a log (.txt file) that you can fill line by line.
    Each line start by the current system date. This class was used in swing application, but could work in a web app.
    Regards,
    Tif                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Copying complete directory structure using java.io.File

    Is there a solution to problem when you want to copy a complete directory structure using java.io.File class as you can copy when using FTP connection.

    Is there a solution to problem when you want to copy
    a complete directory structure using java.io.File
    class as you can copy when using FTP connection.FTP does not have a command to transfer all the files in a directory. FTP clients implement this by invoking single file transfer for each file in a directory.

  • Failed to delete a file in MS Vista using java.io.File.delete()

    while trying to delete a file using java.io.File.delete(), it returns true but the file lies intact.
    i'm sure there is no handle or stream open on the file..
    the same code is running fine in XP..
    if anyone can help me.. thanks

    thanks all..
    the problem is diagnosed further..
    MS Vista does not let a user program to delete any file from 'windows' or 'program files' directories..
    Even when the file is deleted manually thru explorer a confirmation is taken from the administrator.. even when he is logged in..
    i for now have opted to install and use my program in Vista outside 'program files' directory...
    more clarification welcome..

  • Airdrop How Use? Where files go?

    Airdrop How Use? Where files go?

    AirDrop does not work in 2001's Mac OS 9.  If you have Mavericks, pick the necessary forum through this tip:
    http://discussions.apple.com/docs/DOC-2463

  • Access mirror site using java, download files and other information?

    Hi, I have 2 nodes/servers on the system both running webservers and having the same interface, but at a time user will access one node at a time from their browser, but this interface will be able to allow the user to get information from the both the nodes. the information that the user can get is DB stored as well as files on the disk of either node.
    i can manage the DB, cuz there is nothing to it, but how do I get files from the other node?
    currently any files/web documents are all stored in a application directory of the web root and protected by htaccess i believe, so when a user logs on to node one he can access all plain text/binary files along with web content since the web server authorizes the user to access anything in that dir. but at the same time from the same session I want to be able to access files in a mirror site using the same username and password and not having him to enter it again. the username/pass combo is replicated on both the servers, it this possible?
    currently i use the http password protection provided by apache to access one node, but can i use the same session on another machine with the same credentials?
    If this is not possible how can i do this programatically using java? can i do can "ls" on the directory i want on another server and display the list to the user and then when he clicks on that file name i fetch it from the backup/mirror server and have him save it using http or ftp?
    It would be great if we can get a solution to this.
    Thank you very much in advance.
    Ankur

    If you install the web server on different machines, It is possible to share the informations between them.

  • How use java tv in netbeans

    Hi, i download the netbeans 4.1 and how use the library the java tv? I download the example to use the xlet but when compile the file there are many error type ":C:\Documents and Settings\Manu\MobileApplication\src\FirstXletExample.java:13: package javax.tv.xlet does not exist"
    thanks

    hello,
    You should set the class path to the java TV jar file in your netbeans project.
    click right on your project and look for the properties...
    bye
    sebastien

  • File size (using java.io.File)

    Hello all,
    When I want to create an app to be used as file browser, I should like to know the size of a file in a directory. The java.io.File class gives me quite some functionality, but not the functionality to display the file size.
    Does anyone know of a default class that has the functionality to display the file size?
    When no such class exists, I should need to develop it myself. From the top of my head it should be something like this:
    int size = 0;
    int aChar = 0;
    FileReader reader = new FileReader (theFile);
    while (reader.ready() )
        aChar = reader.read()
        size++;
    }The variable size gives me now the number of characters in a file. But this should be done for each file in a particular directory. But does that not ask much CPU performance? Does anyone have an alternative?
    Looking forward to your answer
    Michel

    Hi, I'm having the exact same problem, except that I'm doing a fax system so I can't copy a file while the file is still open. So to check to see if the file is open I have to check the file size in bytes then wait a second and check the file size again. If the file sizes differ then I have to check the next file otherwise I can copy the file. I had a look at the length() method but that will only return the actual length of the file name, not the size of the contents of the file which I need, can anyone please help? Say the file name is 16 ad an a or anything to the file name, if you the call the length() method again it will return 17.

  • Can It Be Done? - Using Java Class Files from a DB

    Hello,
    I am interested in storing a binary java class file in my oracle DB. Then I want to get it out at runtime and execute methods on it. I am planning on casting the object to an interface and executing the methods within. Please let me know if this is possible and where to look for more info, and a code example would be awesome.
    Joe
    [email protected]

    I think you are going to need to serialize the objects and the classes. (Don't get stuck on semantics here, I don't mean use Java Serialization to write the Class instance, I am referring to writing the .class file to a field in the database.) Obviously the instances are what you are interested in (since you mentioned casting them to interfaces and invoking methods on them), but the class definitions will need to either be available already, or stored elsewhere in the database.

  • Getting a file name using java.io.file

    Dear List,
    I am having problems using java.io package. I am reading a string on a linux tomcat server. I am
    trying to parse a windows type filepath (passed by a web-browser-client) and get only the filename. ie. sample.jpg.
    fileName = "c:\\temp\\sample.jpg"
    java.io.File file = new File(fileName);
    onlyFileName = file.getName();
    remember this on linux, and on my server onlyFileName contains "c:\\temp\\sample.jpg" and not sample.jpg as I would expect.
    can any one tell me what I (yet again) dont understand.? Strangely enough when the server is on windows and I am passing a linux string with the fileseperator as a forward-slash, the code manages to derive the correct filename.
    regards
    Ben

    Post this to the beginners forum - has nothing to do
    with native methods.Apologies I thought Java.io would be "native".
    sorry,
    BB

  • Using java class files in JSP

    hi everyone,
    i am trying to import a java file in a JSP page..
    how do i do this???

    hi,
    <%@page import="yourpackagename.*" %>
    or
    <%@page import="yourpackagename.classname" %>

  • Converting types/reading using java.io.file

    I have an existing method that reads a directory.
    File[] list = dir.listFiles();
    I populate a vector from this file list.
    vector.add(list);
    What I am currently trying to do is populate this vector from another source which happens to be another vector. I am basically replacing reading from a directory to reading from a vector that already has the file list. The problem I am having is that the value that I am populating the receiving vector with, the type needs to be "file".
    The vector that I am reading from contains string values of the filepath+filename
    Thanks.

    So, disregarding all that stuff about Vectors, your question is how to convert a String (of a certain form) to a File object? To answer that you could look in the API documentation for File and check out the available constructors. It appears that you have a pathname already, so the second constructor in the list, "new File(pathname)" is what you want.

  • Unable to create file using java.io.File

    I have attached my code
    public boolean validateZip(MultipartFile file, List<String> files) throws Exception {
              String fileName = file.getOriginalFilename();
              File tempFile = new File("C://workspace//tempData//" + fileName);
              LOG.info("Absolute path : " + tempFile.getAbsolutePath());
              ZipFile zipFile = new ZipFile(tempFile);
              LOG.info("No of enteries in the zip : " + zipFile.size());
              //loop through the list and check if the entry is in the zip file
         }The problem is, no exception is thrown in
    ' File tempFile = new File("C://workspace//tempData//" + fileName);
    but, a FileNotFoundException is thrown in
      ZipFile zipFile = new ZipFile(tempFile);Also, it specifies the Absolute Path, but when I check there, there is no file created.
    Any help is appreciated.
    TIA

    ok, when I debug my application for the following code :
    String dir = "C:\workspace";
    String fileName = file.getOriginalFilename();   // file is an instance of a multipart file
    File tempFile = new File(dir, fileName);
    ZipFile zipFile = new ZipFile(tempFile);it runs smooth, no issues, if I run my app, the following line throws a FileNotFoundException...
    ZipFile zipFile = new ZipFile(tempFile);

  • How to load Java properties file dynamically using weblogic server

    Hi,
    We are using Java properties file in Java code. Properties in java properties file are frequently modified. If I keep these properties file in project classpath or as part of war, I will have to redeploy application after each change.
    We are using Weblogic Server.
    Can you please suggest me how can this properties file be loaded at weblogic server startup. Then in that case, how to refer property file in Java code?
    What is the best practice for this?
    Thanks,
    Parshant

    Another alternative is, keep the property file in any pre-defined location. Write a class which reads the properties from the file and returns the one which is requested by caller and deploy this class. Whenever you have to change the properties just update the property file on server and next call to fetch the property should return the updated one.
    Downside of this approach is file I/O everytime. To overcome that you can actually "cache" the properties in a hashmap. Basically when any property if requested, first check the hashmap, if not found then only read from property file and also update in hash map. Next time same property will be returned from hash map itself. The hash map will be cleared at every server restart since its in the memory. You will also need to build a method to clear the hashmap when you update the values in the property file on server.
    This solution would be suitable for small size files and when network overhead of calling a DB needs to be avoided.

Maybe you are looking for

  • Check receipt tab in FBCJ

    Can we receive cheques through FBCJ through check receipt tab. When the present check tab and check lot will be useful. Check receipt process in FBCJ. Ofcourse, check receipts through FBCJ needs again clearing in F-32.

  • Exception "main" javax.xml.ws.soap.SOAPFaultException: Missing SOAP Header

    Hi I need to integrate E-Business Suite with ADF using JAX-WS proxy client. When I tried to invoke a method exposed in webservices, I am getting the below error Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Missing in SOAP Header h

  • Can I  Auto Blend layers in Photoshop Elements?

    I have seen face-swapping tutorials online using the "auto-blend layers" tool In Photoshop CS6. Is there a way to do the same thing in elements? Thanks for the help, Erik

  • Organization Data in Quotations

    Hi experts, Anybody knows where is stored (system table) the Organization Data referref to a Quotation? I tried to view the relationships in CRMD_ORDERADM_H but I'm not able to get it. Is there any way to allocate it withouth debugging process? Thank

  • Change activity calendar for ALL activities at once ?

    Still new to P6, learning as I go... I would like to change the activity calendar--for all existing activities in the schedule--and I would like to change it globally without having to go thru the sched line-by-line. Is this possible? I have this pro