Read form file ok, try to write to same file : FileNotFound

My application starts reads an xml file. When I try to write back to the XML file I get
javax.xml.transform.TransformerException: java.io.FileNotFoundException: file:\C:\Documents%20and%20Settings\alzoid\My%20Documents\Netbeans%20Projects\Laptop\UserSettings.xml (The filename, directory name, or volume label syntax is incorrect)
I did SOP for file.getAbsolutePath() before it read and writes and the ouput is the same:
"C:\Documents and Settings\alzoid\My Documents\Netbeans Projects\Laptop\UserSettings.xml"
Here is the code that reads (works):
public void fillToFile() {
        xmlFile = new File(TO_FILE_NAME);
        try {
            if(xmlFile.exists()) {
                setToPocketPC(db.parse(xmlFile));
            } else {
                createToPocketPC();
        } catch (SAXException se) {
                   se.printStackTrace();  
        } catch (IOException ioe) {
            ioe.printStackTrace();
    }Here is the code that throws the exception:
private void writeDocumentToFile(Document doc,String fileName){
       try {
        xmlFile = new File(fileName);  
        System.out.println(xmlFile.getAbsolutePath());
        source = new DOMSource(doc);
        result = new StreamResult(xmlFile);
        transformer.transform(source, result); //fails here
        xmlFile = null;
        source = null;
        result = null;
       } catch (TransformerConfigurationException tce) {
           tce.printStackTrace();
       } catch (TransformerException te) {
           te.printStackTrace();
       } /*catch (IOException ioe) {
           ioe.printStackTrace();
    }The strange thing is I tested the read/write last week and it worked. I did not change any code. If I copy the file:\c:\Documents%20and%20Settings.... Path into windows explorer it finds the file.
Any suggestions?
Thanks
Al

I'm not sure why either, though the API docs mention "takes File to populate a StreamResult", which really does not make any sense. The File would be populated by the StreamResult. The way it is written would only make sense, at least to me, if the File was being used as input.
Glad I could help. Best of luck.
- Saish

Similar Messages

  • Reading form file data in servlet

    Does anyone have any familiarity with reading data posted by a form such as the following in a servlet:
    <form method="post" action="load_user_file">
    Label: <input type="text" name="label" size="20"><br>
    Data to be sent: <input type="file" enctype="multipart/form-data" size="50"><br>
    <input type="submit" name="Submit">
    </form>
    I would really prefer to get the label data in the "usual way," through the request parameters, but failing that, some way to parse the information "automatically" would be good.
    Thanks in advance for any help!
    - Jerry Oberle

    you want to upload a file....
    the best resource will be to look at MultipartRequest class which can be found at
    www.servlets.com
    anurag
    [email protected]

  • Starting in 2015 I get the following error when I try to import my photos. "The following files were not imported because they could not be read"  -DSC8416.NEF  I've been importing the same type of photos with no errors then 2015 came along and now I can

    Starting in 2015 I get the following error when I try to import my photos. "The following files were not imported because they could not be read"  -DSC8416.NEF  I've been importing the same type of photos with no errors then 2015 came along and now I can no longer import.

    The error message is misleading, the problem is that you need WRITE privileges added to the destination directory tree.
    Assuming you are using the "date" structure that LR defaults to, find the directory that contains the 2014 folder (the one that works) and add WRITE rights to the parent of "2014".
    While you are there, if you want, add "2015" folder to beside "2014" and add READ and WRITE rights to that new directory.

  • 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 read a file as an input stream after it's posted in an HTML form ?

    Hello,
    I want to read client file after it's posted in an HTML form. But, I don't want to upload it to filesystem or database. I want to read posted file as an input stream. How can I do that ?
    thanks in advance...

    A couple of things. If you have a FILE field in your form, the enctype of the form must be multipart/form-data. Check this link
    http://www.htmlhelp.com/reference/html40/forms/form.html
    Also, when a file is uploaded you cannot use the regular methods to get at the name/value pairs or the file itself. You'll have to use a utility like MultiPartRequest or write your own based on the RFC for Multipart requests.
    http://www.servlets.com/cos/javadoc/com/oreilly/servlet/MultipartRequest.html
    You will need some temporary file system to store this and then delete it when you are done with it.
    hth

  • Write Read XML Files not made in LabVIEW

    I have an application that needs to be able to write and read xml files.  My application needs to be able to save the files in such a format that an outside program can use the values saved in the xml file.  On a system restart I need to be able to read in the values that were saved back into the program and populate the multicolumn list box it came from.  My issue really is just reading it back in from the file. 
    I could create a way of writing the xml file with the information in the format needed for the other program.  The problem really is, how do I handle reading in, and then populating controls with the information provided in the xml file with the xml file not in the LabView format. 
    The xml controls that have been provided by NI are not usable in this case. 
    Any suggestions or possible solutions would be greatly appreciated.  Thank you for all of the help ahead of time.

    Try LabXML.

  • Read multiple files and write data on a single  file in java

    Hello,
    I am facing difficulty that I want to read multiple files in java and write their data to a single file. Means Write data in one file from multiple files in java
    Please help me out.
    Naveed.

    algorithm should be something like:
    File uniqueFile = new File();
    for (File f : manyFilesToRead)
       while (readingF)
           write(dataFromF, intoUniqueFile);

  • When I try to open itunes a hazard warning appears reading "The file "itunes library.itl" cannot be read because it was created by a newer version of itunes"

    When i try to open itunes a hazard warning appears reading"the file itunes library.itl cannot be opened because it was created using a newer version of itunes"  so i can't open my itunes on my computer

    Try the following user tip:
    Troubleshooting issues with iTunes for Windows updates
    EDIT: My apologies ... it'd be better to start straight in with the following user tip:
    Empty/corrupt iTunes library after upgrade/crash

  • WCF Service and Sharepoint Form library : How i can read a access a form libray and query a item from file name and read form xml in WCF service ?

    WCF Service and Sharepoint Form library : How i can read or access a form libray and query a item from file name and read form xml in WCF service ?
    Ahsan Ranjha

    Hi,
    In SharePoint 2013, we can take use of REST API or Client Object Model to access the SharePoint objects like Form Library.
    SharePoint 2013 REST API
    http://msdn.microsoft.com/en-us/library/office/dn450841(v=office.15).aspx
    http://blogs.technet.com/b/fromthefield/archive/2013/09/05/working-with-sharepoint-list-data-odata-rest-and-javascript.aspx
    SharePoint 2013 Client Object Model
    http://msdn.microsoft.com/en-us/library/office/fp179912(v=office.15).aspx
    http://msdn.microsoft.com/en-us/library/office/jj193041(v=office.15).aspx
    With the retrieved file, we can then use XmlDocument object to parse it and get the values you want:
    http://weblogs.asp.net/jimjackson/opening-and-reading-an-xml-file-in-a-document-library
    http://stackoverflow.com/questions/1968809/programatically-edit-infopath-form-fields
    Best regards
    Patrick Liang
    TechNet Community Support

  • How to modify a datafile using file read and file write

    I have a datalog file containing port and DMM setup information.  I want to read this file into an aray, update or modify it, and write it to a file.  I can read the file in, but I am at a loss on how to modify it since it is stored in an indicator.  Any suggestions?

    The simplest thing is to replace your indicator by a control, and to use a local variable to write your data into the control.
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        

  • How to read XML file and write into another XML file

    Hi all, I am new to JAVAXML.
    My problem is I have to read one XML file and take some Nodes from that and write these nodes into another XML file...
    I solved, how to read XML file
    But I don't know how to Write nodes into another XML.
    Can anyone help in this???
    Thanks in advance..

    This was answered a bit ago. There was a thread called "XML Mergine" that started on Sept 14th. It has a lot of information about what it takes to copy nodes from one XML Document object into another.
    Dave Patterson

  • A need a function module to read a file and write back into it

    Hello ,
    My requirement is to provide the path to a file , read the file contents and then write back to it.
    Thanks,
    Mridu.

    Hi ,
    Use combination of these three FM's , A nice documentation is given for them by SAP .
    1.)  F4_FILENAME
    2.) GUI_UPLOAD
    3.) GUI_DOWNLOAD
    revert back if any queries
    reward points if helpful

  • User to write/read in file folder

    Hi Gurus,
    We are testing File receiver with NFS protocol and the server is running on UNIX system.
    So Which user will write/read these files in the foder.We could not able to write files even though we have given right access.
    Kum

    So Which user will write/read these files in the foder.We could not able to write files even though we have given right
    access.
    Ask the target-folder admins to provide full access to a user and then use this user in your channel.....user should have 777 access.... in UNIX it is done through chmod 777 ..... for exact notation/ format just make a search on google (the folder-admins would be knowing the format)
    Regards,
    Abhishek.

  • New pc with windows 8.1, downloaded and installed cs5,no problem open bridge and cs5, but can't read raw file , try to update, can't complete or failed updating, please help

    new pc with windows 8.1, downloaded and installed cs5,no problem open bridge and cs5, but can't read raw file , try to update, can't complete or failed updating, please help

    Sounds like you somehow got the mac version.
    Download the windows 6.7 camera raw update from this link:
    Adobe - Photoshop : For Windows : Camera Raw 6.7 Update

  • Whenever i try to download a rather large file i continue to get the "could not read source file" error. Tried new profile, uninstalling and looking for the compreg.dat file to delete nothing is working. Please help

    whenever i try to download a rather large file i continue to get the "could not read source file" error. Tried new profile, uninstalling and looking for the compreg.dat file to delete nothing is working. Please help

    Did you reinstall CS3 after CC?
    For that matter, doing an in-place upgrade on the OS is always a gamble with Adobe programs. Reinstalling all the versions you need, in order, would probably solve your problem.
    And you shouldn't need to save as IDML after opening the .inx in CC.

Maybe you are looking for

  • TS1702 Not sharing documents with photos in by email e.g. from pages or explain everything.....apple id issue?

    I've got a work ipad.  I have 3 or 4 different email accounts on my ipad. I have several documents in pages which email in to work easily. If I add any pictures into the document in pages ir refuses point blank to email them in to myself via any emai

  • Count Specific Value in Column as a Total

    I am using Oracle 10g, In my worksheet i have created column using Decode Function.I would like to count Flag='Y'(not using group sort). Could anybody help me on this problem Eg: Entered Employment At Exit Y Y N Y N Y Y Total = 5 Thanks, Vikram

  • How to select all objects in a document?

    AI newbie question: I have an active document with two linked files, I need to select both of these in a script and embed both.  Then I will be selecting these separate and performing various actions on each. In JavaScript, once I have the document o

  • Re: dataload validation

    Hi Everyone, I developed a cube with 5 dimensions like agent,measure,time,value,agency etc.and i have data file to load the data into cube.when i tried to load the data first time it is loaded partially because of someof agent members are no there in

  • Media browser has no directory structure

    Hi, probably a pretty dumb question, but here's my problem: the media browser in PrPro CS6 worked fine untill yesterday, now it doesn't display the directory structure in the left pane anymore. I can still reach the required directories through a sho