File file = new File(URL) - no can do on 1.3?????

I'm using java v1.3 and when I try to use the constructer File file = new File(URL) I get this error :
C:\myservlets\TestServlet.java:26: cannot resolve symbol
symbol : constructor File (java.net.URL)
location: class java.io.File
     file = new File(path);
I have looked at the File Class API and there is such a constructer, is it because I am using v1.3, how can I get pass this without installing v1.4?

I have looked at the File Class API and there is such
a constructer, is it because I am using v1.3, how can
I get pass this without installing v1.4?The File(java.net.URL) constructor is not available in 1.3, only in 1.4+...
Why not use the File (String pathname) constructor?
bbm1277

Similar Messages

  • Reading file from a folder : File dir = new File(URL+aFile_to_add);

    Hi,
    Trying to read files from a dir on my site using a JSP and bean. I've tried nearly every option for the filepath I can think of and it doesn't seem to be finding the file...
    Here's the bit:
    String URL = "images\\wedding_photos\\";
    File dir = new File(URL+aFile_to_add);
    String[] files = dir.list();
    It's working locally, but I obviously had to change the path from c://... to the above.
    The full code is listed below in the addWedding Method
    The method removes the .jpg from the file name and then writes the new file name to a database
    Thanks for any insight.
    Regards
    Jim
    public String addWedding(String aFile_to_add)
    String feedback = "unset in scrubWedding";
    try
    String URL = "images\\wedding_photos\\";
    Class.forName("org.gjt.mm.mysql.Driver");
    java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:mysql://localhost/rhwedd2_shop?user=**********&password=*******");
    java.sql.Statement statement = connection.createStatement();
    File dir = new File(URL+aFile_to_add);
    String[] files = dir.list();
    if (files == null)
    feedback = "Sorry, couldn't find the file "+aFile_to_add+"...no files have been added.";
    else
    for (int i=0; i<files.length; i++)
    // Get filename of file or directory
    String filename = files;
    String no_extension;
    //convert string array element into a char array
    char [] charsfilename = filename.toCharArray();
    int newlength = charsfilename.length -4;
    no_extension = String.valueOf(charsfilename,0,newlength);
    filesAdded = filesAdded+", "+no_extension;
    // Show the new file names in stack trace without extension
    //System.out.println("String no_extension " + no_extension );
    statement.executeUpdate("INSERT INTO items VALUES ('"+no_extension+"',5,'"+aFile_to_add+"')");
    // write to table with item_id and weddingid
    feedback = "The following files have been added..."+filesAdded;
    if (statement != null )
    statement.close();
    if ( connection != null )
    connection.close();
    catch(Exception e)
    feedback = "Into the catch";
    e.printStackTrace(System.err) ;
    return feedback;
    }//end addWedding

    String URL = "images\\wedding_photos\\";
    File dir = new File(URL+aFile_to_add); ok, ok, I'll answer...
    1) What gives you the impression that the relative directory "images\\..." exists (or, in other words, what makes you think your current directory is the parent of "images"?

  • Why is my powerpoint not working 10.9? i can't play my existing file and new files that i work..? how to fix that one..? pls help..!

    why is my powerpoint not working 10.9? i can't play my existing file and new files that i work..? how to fix that one..? pls help..!

    R Cubss,
    You might want to read down this thread. There are a lot of tips-n-tricks, and maybe one will be right for you.
    http://www.adobeforums.com/webx/.59b6565c/43
    Good luck,
    Hunt

  • Question on File f = new File(....

    Im using an ftp program. It requires a type like file.
    I want to do something like this:
    File f = new File("C:\");
    Except I cant convert file to string. The file is used to set the local directory and remote directory. How can i set a file to c:?
    Im just a bit confused. I never came across this before.
    ANy help or assistance would be greatly appreciated.

    ahhhhhhhh crapola...I was missing the last slash!!!!!
    Sorry to waste your time.
    THanks so much though..

  • Rename recorded avi file with new file name

    Dear all,
    I'm working on capturing video from a web-cam and storing files which use the time stamps as the file names. As my application must start storing the data as quick as possible, so I need to start the realized processor, create/open the datasink in advance, otherwise there will be a 10 sec time lag. In creating the datasink, I set the medialocator pointed to a temp file:TEMP.avi
    I store the files in the same TEMP.avi for each recording and I want to rename the TEMP.avi using the time stamp as the file name.
    I've tried the setOutputLocator() and tried to set the output as 2003_11_02_183023.avi, but it only work once, the next record still use the previous name.
    I've tried the renameto(), but it doesn't work.
    I've also tried the renameFile(), but it prompt "non static .. can not be referenced to static content".
    Are there any way to solve this problem ? It seems to be a simple file renaming problem, but ..
    Thanks in Advance !
    kan

    byte[] aviData = ...; // data from TEMP.AVI
    File file = new File(timestamp);
    FileOutputStream out = new FileOutputStream(file);
    out.write(aviData);
    out.flush();
    out.close();

  • Why is overwritten file opening new file for all backed up versions of file?

    I accidentally overwrote an important file by accidentally selecting the wrong file to be replaced.  I was at a client's premises when it happened and the external time machine drive was not connected. So there should be no problem because my time machine hard drive was at home with the old file in the time machine back ups right? Wrong.
    When I go into time machine, whether through searching in the individual folder or "Enter Time Machine" method, it always opens the new overwritten version of the file!
    The original just has to be on the external Time Machine hard drive! It wasn't connected to the computer when I overwrote the file on my computer. So why are all versions of the back up opening the new version of the file and not opening the back versions of the file?! What good is Time Machine if it is opening new versions of the overwritten file when you want to open the old versions of the backed up file?

    tryb4buy wrote:
    Am I the first person ever to try and recover overwritten files with Time Machine?
    Of course not. Plenty of people use TM to recover files or restore entire disks regularly. What you are describing is very strange, which suggests that either there is some rogue bug in TM, or that events have not occurred in quite the way that you think or are describing.
    Clearly, there is no way that a file can magically appear on your backups before you created it, when the drive is not attached. So the only way it could have got there is for TM to run a backup and somehow corrupt all versions with the new file. So did TM run a backup before you attempted a restore?
    How far back do your backups for this file go? How often did you attach the external disk to allow TM to run backups?
    What version of OS X are you on?
    Are you using the TM application to browse through your backups, or the Finder?

  • Photoshop CS5 crashes when opening file/creating new file

    I can load up CS5 and its fine. I then go to open or create a file and it just crashes.
    Can someone help me please
    I really need photoshop for my photography
    Cheers
    Lunty

    Photoshop uses OpenGL for some things that won't function if you disable it, but for the most part Photoshop will work fine.  Things you will miss include:
    Alt-right click and drag mouse gestures for changing brush size/hardness won't show you a preview of your brush size/hardness, just an outline.
    Smooth zoom and panning.
    Some 3D functions of the Extended edition.
    Some performance improvements in the display.
    Adobe has done a great job of making almost all of Photoshop work well without OpenGL, but I encourage you to visit the following site and download the latest video drivers for your card.  It may clear up all the Photoshop problems and possibly others you don't know you have yet.
    http://www.amd.com/us/Pages/AMDHomePage.aspx   (Note the "Download Drivers" section to the upper-right).
    -Noel

  • Saving File with new file name

    I am subclassing JFileChooser and implementing ActionListener for being able to save and open files.
    I am using different file extensions (.ac and .ps), and when saving, I first check that the file name has the right extension.
    If it doesn't, I add the right extension.
    But for some reason it doesn't show my saved new file, even though in the debugger it goes through all the code of saving.
    Here is the main portion of my code before the code of saving (adaptee is my JFileChooser):
    File ananyaFile = adaptee.getSelectedFile();
    String name = ananyaFile.getName();
    int l = name.length();
    if (!(l >= 4 && name.charAt(l - 3) == '.' &&
    ((adaptee.getFileFilter() == adaptee.acExtensionFilter &&
    name.charAt(l - 2) == 'a' && name.charAt(l - 1) == 'c') ||
    (adaptee.getFileFilter() == adaptee.psExtensionFilter &&
    name.charAt(l - 2) == 'p' && name.charAt(l - 1) == 's'))))
    if (adaptee.getFileFilter() == adaptee.acExtensionFilter)
    name = name + ".ac";
    ananyaFile = new File(name);
    adaptee.setSelectedFile(ananyaFile);
    else if (adaptee.getFileFilter() == adaptee.psExtensionFilter)
    name = name + ".ps";
    ananyaFile = new File(name);
    adaptee.setSelectedFile(ananyaFile);
    Why does it not show my saved new file? Do I have to set it somewhere else?
    Thanks for your time!

    Ok, I put the code which adds the extension
    File ananyaFile = this.getSelectedFile();
    if (ananyaFile == null)
       return;
    String name = ananyaFile.getName();
    int l = name.length();
    if (!(l >= 4 && name.charAt(l - 3) == '.'  &&
       name.charAt(l - 2) == 'a' && name.charAt(l - 1) == 'c')  
       name = name + ".ac";
       ananyaFile = new File(name);
       this.setSelectedFile(ananyaFile);
    }into the approveSelection method of my subclass of JFileChooser.
    If someone wants to open a file without writing the extension and the file with the extension (which was added in my code) exists, it does get opened.
    Also, if someone wants to save a file without writing the extension and the file with the extension (which was added in my code) exists, it does ask if you want to replace the file (as I have programmed).
    But if you say yes, or if you want to save a file without the extension that doesn't yet exists (with the extension), it doesn't save it.
    However, saving works fine if someone writes the full file name into the File name box.
    Well, I would like to allow the user not to write the extension not only for opening a file, but also for saving a file.
    Please help! I am getting pretty desperate! Thanks!

  • Display .doc file in new window by url

    Hi all,
    I hope someone got a quick an easy solution for this one.
    I want to access and display (open/save) a .doc file in a new separate window by using createExternalWindow(docUrl, xxx, xxx), where docUrl is a path on the local webAS. Right now I access the file like this:
    File doc = new File("apps/local/filename.doc");
    wdComponentAPI.getWindowManager().createExternalWindow(doc.getURL(), "", false).open;
    This does not work though, since it gives me the absolute path from the hard drive letter and down, ie: c:/usr/sap/../filename.doc
    We havent installed Office Integration on our webAS.
    Anyone? All help help is appreciated. This doesn't feel like it should be a big issue?!
    Best regards,
    Andreas

    Andreas,
    Here is probably not the optimal and not the most intuitive way to perform this task, but anyway:
    1. In View controller context create attribute with type <b>binary</b>, let us name it <b>MyDoc</b>
    2. In View controller source define private variable
    private ISimpleType _msWordType
    3. In View controller wdDoInit method place the following:
    _msWordType = wdContext
      .getNodeInfo()
        .getAttribute("MyDoc")
          .getModifiableSimpleType();
    ((IWDModifiableBinaryType)_msWordType).setMimeType( WDWebResourceType.DOC );
    ((IWDModifiableBinaryType)_msWordType).setFileName( "MyMsWordDocument.doc" );
    4. Use the following docUrl when calling createExternalWindow
    /* Load document content first */
    final byte[] documentContent = loadDocumentBytes();
    /* And now the trick itself */
    final String docUrl = _msWordType.format( documentContent );
    We successfully apply this technique to display photo from employee profile loaded from database
    VS

  • How to get the target file name from an URL?

    Hi there,
    I am trying to download data from an URL and save the content in a file that have the same name as the file on the server. In some way, what I want to do is pretty similar to what you can do when you do a right click on a link in Internet Explorer (or any other web browser) and choose "save target as".
    If the URL is a direct link to the file (for example: http://java.sun.com/images/e8_java_logo_red.jpg ), I do not have any problem:
    URL url = new URL("http://java.sun.com/images/e8_java_logo_red.jpg");
    System.out.println("Opening connection to " + url + "...");
    // Copy resource to local file                   
    InputStream is = url.openStream();
    FileOutputStream fos=null;
    String fileName = null;
    StringTokenizer st=new StringTokenizer(url.getFile(), "/");
    while (st.hasMoreTokens())
                    fileName=st.nextToken();
    System.out.println("The file name will be: " + fileName);
    File localFile= new File(System.getProperty("user.dir"), fileName);
    fos = new FileOutputStream(localFile);
    try {
        byte[] buf = new byte[1024];
        int i = 0;
        while ((i = is.read(buf)) != -1) {
            fos.write(buf, 0, i);
    } catch (Throwable e) {
        e.printStackTrace();
    } finally {
        if (is != null)
            is.close();
        if (fos != null)
            fos.close();
    }Everything is fine, the file name I get is "e8_java_logo_red.jpg", which is what I expect to get.
    However, if the URL is an indirect link to the file (for example: http://javadl.sun.com/webapps/download/AutoDL?BundleId=37719 , which link to a file named JavaSetup6u18-rv.exe ), the similar code return AutoDL?BundleId=37719 as file name, when I would like to have JavaSetup6u18-rv.exe .
    URL url = new URL("http://javadl.sun.com/webapps/download/AutoDL?BundleId=37719");
    System.out.println("Opening connection to " + url + "...");
    // Copy resource to local file                   
    InputStream is = url.openStream();
    FileOutputStream fos=null;
    String fileName = null;
    StringTokenizer st=new StringTokenizer(url.getFile(), "/");
    while (st.hasMoreTokens())
                    fileName=st.nextToken();
    System.out.println("The file name will be: " + fileName);
    File localFile= new File(System.getProperty("user.dir"), fileName);
    fos = new FileOutputStream(localFile);
    try {
        byte[] buf = new byte[1024];
        int i = 0;
        while ((i = is.read(buf)) != -1) {
            fos.write(buf, 0, i);
    } catch (Throwable e) {
        e.printStackTrace();
    } finally {
        if (is != null)
            is.close();
        if (fos != null)
            fos.close();
    }Do you know how I can do that.
    Thanks for your help
    // JB
    Edited by: jb-from-sydney on Feb 9, 2010 10:37 PM

    Thanks for your answer.
    By following your idea, I found out that one of the header ( content-disposition ) can contain the name to be used if the file is downloaded. Here is the full code that allow you to download locally a file on the Internet:
          * Download locally a file from a given URL.
          * @param url - the url.
          * @param destinationFolder - The destination folder.
          * @return the file
          * @throws IOException Signals that an I/O exception has occurred.
         public static final File downloadFile(URL url, File destinationFolder) throws IOException {
              URLConnection urlC = url.openConnection();
              InputStream is = urlC.getInputStream();
              FileOutputStream fos = null;
              String fileName = getFileName(urlC);
              destinationFolder.mkdirs();
              File localFile = new File(destinationFolder, fileName);
              fos = new FileOutputStream(localFile);
              try {
                   byte[] buf = new byte[1024];
                   int i = 0;
                   while ((i = is.read(buf)) != -1) {
                        fos.write(buf, 0, i);
              } finally {
                   if (is != null)
                        is.close();
                   if (fos != null)
                        fos.close();
              return localFile;
          * Returns the file name associated to an url connection.<br />
          * The result is not a path but just a file name.
          * @param urlC - the url connection
          * @return the file name
          * @throws IOException Signals that an I/O exception has occurred.
         private static final String getFileName(URLConnection urlC) throws IOException {
              String fileName = null;
              String contentDisposition = urlC.getHeaderField("content-disposition");
              if (contentDisposition != null) {
                   fileName = extractFileNameFromContentDisposition(contentDisposition);
              // if the file name cannot be extracted from the content-disposition
              // header, using the url.getFilename() method
              if (fileName == null) {
                   StringTokenizer st = new StringTokenizer(urlC.getURL().getFile(), "/");
                   while (st.hasMoreTokens())
                        fileName = st.nextToken();
              return fileName;
          * Extract the file name from the content disposition header.
          * <p>
          * See <a
          * href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html">http:
          * //www.w3.org/Protocols/rfc2616/rfc2616-sec19.html</a> for detailled
          * information regarding the headers in HTML.
          * @param contentDisposition - the content-disposition header. Cannot be
          *            <code>null>/code>.
          * @return the file name, or <code>null</code> if the content-disposition
          *         header does not contain the filename attribute.
         private static final String extractFileNameFromContentDisposition(
                   String contentDisposition) {
              String[] attributes = contentDisposition.split(";");
              for (String a : attributes) {
                   if (a.toLowerCase().contains("filename")) {
                        // The attribute is the file name. The filename is between
                        // quotes.
                        return a.substring(a.indexOf('\"') + 1, a.lastIndexOf('\"'));
              // not found
              return null;
         }

  • File Download - new Problem

    Hi java guru's
    I'm trying to write a download pgm using servlet and JSP. The actual problem is, when i'm trying to download a file, the output stream writes all the comtent of the file on the browser itself even if it's a .exe file instead of opening a "Save as" dialog box
    Can you guru's suggest me a best way to overcome this problem!
    Thanks in advance

    Hello friends,
    We can download any files in two ways
    1. calling java script function
    2. read/write operation(io).
    Both codes are working fine. try it and if u face any problem.Please let me know,
    Friendly,
    Jawahar
    bangalore. India
    [email protected]
    =================================
    java script code
    ==============================
    <%
    <!-- file relative path is here -->
    String path ="/jsp/xxx.xls";
    <!-- file name is here -->
    String fileName="xxx.xls";
    %>
    <html>
    <head>
    <title>Down load forms</title>
    </head>
    <body onLoad="window.open('<%=path%>');">
    <table border="0" align="center" width="100%">
    <tr><td height="181"><font face="verdana" color="#5599cc" size="2" align="center">you have selected the file <%=fileName%</font> </td></tr> </table></body></html>
    ==========================================
    Read/write IO operation is here
    ==========================================
    <%
    String files = null;
    String fileName=null;
    <!-- file path is here -->
    String file=".... any path";
    File f = new File(file);
    FileInputStream in = new FileInputStream(f);
    int length = (int)f.length();
    if(length != 0)
    byte[] buf = new byte[length];
    ServletOutputStream op = response.getOutputStream();     
    response.setContentType ("application/octet-stream");
    response.setHeader("Content-Disposition", "attachment; filename=\""+fileName+"\"");
    while ((in != null) && ((length = in.read(buf)) != -1))
    System.out.println("BUFFER $"+buf.length+"$");
    System.out.println("Bytes read in: " + Integer.toString(length));
    op.write(buf,0, buf.length);
    op.close();
    %>     
    <%@ page import="java.io.*,javax.servlet.*,java.util.*,java.sql.* " contentType="text/html" %>
    <html>
    <head>
    <title>Welcome to the download form page</title>
    </head>
    <body bgcolor=#FFFFFF>
    ==========================================

  • Reading text file, Replace string, Write to new file....

    I'm kind a lost of on this problem. Using the BufferedReader class and BufferedWriter class, develop an application that reads lines of text from a file. Replace any occurrence of the word *?the?* with *?JAVAJAVA?* and change all characters to upper case before writing each line to a different text file named outfile.txt. Finally, have your application use the appropriate method on the File class to return the absolute path of the outfile.txt file and output the path to the screen.
    * Created December 10, 2008
    * @author Fausto Rivera
    * Colorado Technical University - Online Campus
    * IT271-0804B-02 Intermediate Object Oriented Programming II
    * Phase 2 IP
    * Instructor: Cheryl B Frederick
    import java.io.File;
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    public class FRiveraReader {
          public static void main(String[] args) {
          // instantiated a new application object to initialize the application
          FRiveraReader application = new FRiveraReader();}
    //      application.getReadfr();  // call to openFile method
    //      application.doWritefr(); // call to readRecords method
    //      application.closeFile();  // call to closeFile method
    public FRiveraReader(){}
      public void getReadfr (String friveraInfile, String fr []){
       int i;
       File fileName = makeAbsoluteFilename(friveraInfile);
       try{
        BufferedReader reader = new BufferedReader(new FileReader(fileName));
        String line = reader.readLine();
         i=0;
          while (line != null) {
           fr[i] =line;
           line = reader.readLine();
        i++;
      reader.close();
    catch(IOException e) {
    System.out.println("Error with reading file:" + friveraInfile);
    }//end of getOrder method
    public void doWritefr(String friveraOutfile, String fw[]){//String name of file, String array to be written
    int i;
    File fileNameout = makeAbsoluteFilename(friveraOutfile);
    try {
    BufferedWriter writer = new BufferedWriter(new FileWriter (fileNameout));
      i=0;
      while (fw[i] != null) {
       writer.write(fw[i] + "%n"); //need delimiters between data in file;also, reader reads a line
       i++;
      writer.close();
    catch(FileNotFoundException e) {
    System.out.println("File not found");
    catch(IOException e) {
    System.out.println("Error with reading file:" + friveraOutfile);
    }//end of getOrder method
    private File makeAbsoluteFilename(String friveraOutfile)//these 2 classes used to resolve file name
            File file = new File(friveraOutfile);
            if(!file.isAbsolute()) {
                file = new File(friveraOutfile);
            return file;

    I have modified my code as far as being able to create a text file, write to string, and change to upper case. Now, how can I connected input to the output stream and then replace all the instances of the string "the" for the string "JAVAJAVA"? When the file is created, it goes into a loop writing the following:
    nJAVA.IO.BUFFEREDWRITER@19821F%nJAVA.IO.BUFFEREDWRITER@19821F%nJAVA.IO.BUFFEREDWRITER@19821F%nJAVA.IO.BUFFEREDWRITER@19821F%nJAVA.IO.BUFFEREDWRITER@19821F%nJAVA.IO.BUFFEREDWRITER@19821F%
    Here is my modified code
    import java.io.File;
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    public class FRiveraReader {
    public FRiveraReader() {}
    private static final String inFile = "C:\\Documents and Settings\\Fausto Rivera\\My Documents\\NetBeansProjects\\Rivera_F_IT271_0804B_02_PH2_IP\\friverainfile.txt";//the path name of your file
      public void myReadfr (){
       try {
        BufferedReader reader = new BufferedReader(new FileReader(inFile));
        //String "JAVAJAVA" = String "the";
        System.out.println(inFile);
        String line = reader.readLine();
          while (reader != null) {
           line = reader.readLine();
      reader.close();
    catch(IOException e) {
    System.out.println("Error with reading file:" + inFile);
    }//end of myReadfr method
    public void myWritefr(){//String name of file, String array to be written
    File outFile = new File ("C:\\Documents and Settings\\Fausto Rivera\\My Documents\\NetBeansProjects\\Rivera_F_IT271_0804B_02_PH2_IP\\myoutFile.txt");
    try {
    BufferedWriter writer = new BufferedWriter(new FileWriter (outFile));
    String newline = writer.toString() .toUpperCase();
      while (writer != null) {
       writer.write(newline + "%n"); //need delimiters between data in file;also, reader reads a line
      writer.close();
    catch(FileNotFoundException e) {
    System.out.println("File not found");
    catch(IOException e) {
    System.out.println("Error writing file:" + outFile);
    }//end of getOrder method
    private File makeAbsoluteFilename(String myoutFile)//these 2 classes used to resolve file name
            File file = new File(myoutFile);
            if(!file.isAbsolute()) {
                file = new File(myoutFile);
            return file;
      }Edited by: FRiveraJr on Dec 17, 2008 12:10 PM

  • How to create new file and popup a Save As Dialog?

    I want to create a new file and then popup a Save As Dialog to save the new created file.
    I have tried to use the JFileChooser as the following code:
    =============================================
    JFileChooser jfc = new JFileChooser();
    File f = new File("c:\\text.txt");
    jfc.setSelectedFile(f);
    int returnVal = jfc.showSaveDialog(this);
    if(returnVal == JFileChooser.APPROVE_OPTION) {
    f = jfc.getSelectedFile();
    =============================================
    I can't found the created file execute the program, anyone can tell me whats going wrong of my code or give me some advice?
    Thanks a lot.

    Actally, I want to generate a file and specific the
    name and the location to save it.
    And solution to do this if don't use the JFileChooser?Use a JFileChooser to choose a file name (you can select the directory and type the filename into a field). Once you have the file name you can open a FileOuputStream or FileWriter and write to the file you have just defined. If this file does not exist then it will be created.
    If you want to confirm before overwriting an existing file then just put up a confirm dialog if the file exists (File.exists()).

  • Create a new file

    Hello,
    I have a signed applet but it does not allow me to create new files. I can only read and create new folders.
    for example, the code:
    myFile.mkdirs();works ok
    but with:
    myFile.createNewFile();I get the exception:
    java.io.IOException: Access is denied
         at java.io.WinNTFileSystem.createFileExclusively(Native Method)
         at java.io.File.createNewFile(Unknown SourceWhat�s going wrong?
    thanks,
    Fabr�cio Lemos

    I'm having the same problem. I noticed that the mkdirs() method also creates a subdirectory with the name of what's supposed to be a file name :
    File MyPropertyFile = new File("c:\\Program Files\\VAMPStatistics","VAMPProperties.txt");
    /* what I want to do now is create a directory c:\Program Files\VAMPStatistics and a file named VAMPProperties.txt */
    MyPropertyFile.mkdirs();
    MyPropertyFile.createNewFile();
    FileOutputStream output = new FileOutputStream(MyPropertyFile);
    After I run this I get
    Exception in thread "main" java.io.FileNotFoundException: c:\Program Files\VAMPStatistics\VAMPProperties.txt (Toegang geweigerd)
    at java.io.FileOutputStream.open(Native Method)
    and
    I see that I have a directory on my pc
    c:\Program Files\VAMPStatistics\VAMPProperties.txt
    so VAMPProperties.txt is created as a subdirectory, not as a file.
    So what happened is that when I call the constructor for FileOutputStream, MyPropertyFile object is interpreted as a complete directory name, not a directory and a file name
    I notice that when i remove the mkdir() call, then there's no problem.

  • I'm trying to write a VI that updates a file each time it is run, but on a new day a new file is created which is updated until a new day begins.

    I have written a VI to create and update a file as many times as needed on any given day. On any subsequent day a new file is created which for that day will be updated each time the VI is run and so on. The problem is that when I run the VI the first time of a new day, ie when the file is created only data is written to the file and not the header data. When the file is appended, header data, and regular data is properly written to the file. Can anyone tell me how to correct this problem? A copy of the VI that I wrote is attached.
    Thanks,
    Chuck M.
    Solved!
    Go to Solution.
    Attachments:
    File - create new on date change.vi ‏15 KB

    You had the header information written when there wasn't an existing file, then you overwrote that file with another file consisting only of the data because you wired the "append to file? (new file:F)" the same for both functions (F causes it to create a new file).  I put the header writing function in a Case structure because you only want it to execute when this is a new file (otherwise it'll overwrite what's there).  Wire the path straight through the False case.  I wired a TRUE to the data writing function to always append (because there will always be a file by the time the program gets there).
    Jim
    PS - a few other observations
    Avoid sequence structures
    You don't need the property node
    Use Path functions (not string)
    Message Edited by jcarmody on 04-13-2009 05:58 PM
    Jim
    You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
    Attachments:
    examp.jpg ‏19 KB

  • New File() is not working on MAC

    Hi,
    I don't know exactly what is the problem,since i search in forums.
    but in my code
    File f = new File("/Users/sky/Desktop/dist/test.txt");
    is not working on Mac os.
    Please help !

    skymania wrote:
    On window it will give output : success
    On Mac it will give nothing.
    On window and mac both file is not exist (physically). Bull.
    Simply doing new File(...) does NOT create a file on disk, no matter what the OS.
    On Windows, before running the Java code:
    C:\>dir C:\CONFIG.SYS
    02/05/2008  01:06 PM                 0 CONFIG.SYS
    C:\>dir C:\zzzzz
    File Not FoundThen I run this Java:
    package scratch;
    import java.io.File;
    * Copyright (c) 2009 Tone Software Corporation
    * @author Jeff Verdegan
    public class NewFileDoesNotCreateAFileOnDisk {
      public static void main (String[] args) throws Exception{
        File f1 = new File("C:/CONFIG.SYS");
        File f2 = new File("C:/zzzzz");
        System.out.println(f1.getCanonicalPath () + ".exists() is " + f1.exists ());
        System.out.println(f2.getCanonicalPath () + ".exists() is " + f2.exists ());
    }and I get this result:
    C:\CONFIG.SYS.exists() is true
    C:\zzzzz.exists() is falseAnd then I do the dir again, and I get the same results.
    Thus proving that new File does NOT create a file on the disk.
    If you would bother to read the docs for the File class like I suggested, you'll see a way that you can create a file on disk.
    And if you read my other comments, you'll see how to create a file as you write to it.

Maybe you are looking for

  • Backing up apps that arent in my itunes library?

    Hello. This has been happening for quite some time and im curious why. When i back up my phone, a window pops up that says something like "There are apps on your phone that have not been backed up yet, would you like to back them up" and in small pri

  • Error -200152 in oax_AI Config (DAQmx).vi

    I have been in contact with NI support regarding this issue.  They recommended posting to the forums for faster help.  I am posting a screenshot of my MAX and also my VI (it requires more subVIs to run, let me know if you need to see any of these). 

  • Service Packages are changing users default calendars

    I'm currently testing Communications Suite 5 cal server 6.2 schema 2. I have everything up and running but I'm running into an issue with with assigning service packages to users though. I created all the users from the command line and I used -k leg

  • Restriction settings for mac

    I just finished iOS 5 and Lion updates for all devices.  I am using the restrictions setting in iOS so that no one can turn off location services (I realize there are other ways around, but this seems like a good idea to help track a lost/stolen devi

  • Do you have customer with more than 100 users ?

    Hello We think to place business One to a One hundred users customer. Do you know if it will works fine ? Do you have an existing customer with more than 100 users ? Thanks for answers. Julien