Write file problem

Hi, guys
I have a problem to write a file using PrintWriter. What I want to do is my program takes file name and path, if the same name file exist in the folder, data ppended at the end of the existing file, otherwise it generates the new file.
File file_out = new File(path, title);
       //System.out.println(file_out.getName());
       if (fileName_out.getName().equals(""))
         JOptionPane.showMessageDialog(this,"Invalid File name",
               "Invalid File nmae",JOptionPane.ERROR_MESSAGE);
         return(false);
     else
               try
                    boolean created = file_out.createNewFile();
                    if(created)
                        fileOutput = new PrintWriter(new FileWriter(fileName_out));
                        return(true);
                    else
                        fileOutput = new PrintWriter(new FileWriter(fileName_out,true));
                        fileOutput.println("File Name"+"\t"+"Slope(m)"+"\t"+"y-intercept(b)"+"\t"+"Correlation(r)");
                        return(true);
                catch (IOException exc)
                     System.err.println("Can not open the file " );
                     return(false);
                }I don't know what's wrong with, when I run this program, it doesn't make any file and issues NullPointerException.
Anybody got solutions?
Thanks a lot,

File file_out = new File(path, title);
       //System.out.println(file_out.getName());
       if (fileName_out.getName().equals("")) Is there a reason why you assign something to the variable file_out and then start working with a different variable fileName_out? Which you probably haven't assigned anything to, leading to NullPointerExceptions?

Similar Messages

  • Read and write file problem

    hello
    I have web application and I try using servlet to upload an image
    upload proccess works fine
    example
    1. I upload the the file C:\images\books\mybook.gif into
    temp folder
    2. other actions
    3. I want to write the fole mybook.gif into othet folder
    this process oerks fine on my home pc
    but I becom an ecxeption by webprovider
    /home/mydomain/public_html/projects/tempData/C:\images\books\mybook.gif(No such file or directory)what shoud be the problem and how to solve this issue
    thanks

    here is the code of the uploadservlet
    public void doPost(HttpServletRequest request, HttpServletResponse response)
                   throws ServletException, IOException
        PrintWriter out = null;
        String tempUploadDir = request.getSession().getServletContext().getRealPath("/")+"MyTemp"+File.separator;
         try
              out = response.getWriter();
             response.setContentType("text/html");
             MultipartRequest parser = new ServletMultipartRequest(request,
                                                                               MultipartRequest.MAX_READ_BYTES,
                                                                               MultipartRequest.IGNORE_FILES_IF_MAX_BYES_EXCEEDED,
                                                                               null);
                 Enumeration files= parser.getFileParameterNames();
                      while(files.hasMoreElements()){
                                boolean sizeOK    = true;         
                                String name       = (String)files.nextElement();
                                String filename   = parser. getBaseFilename(name);
                              InputStream ins   = parser.getFileContents(name);
                              if((parser.getFileSize(name) / 1024) > AppConstants.MAX_READ_BYTES){sizeOK = false;}
                         if(sizeOK){
                              if (ins!=null)
                                      BufferedInputStream input = new BufferedInputStream(ins);
                                   FileOutputStream outfile = new FileOutputStream(new File("MyTemp",filename));
                                             int read;
                                             byte[] buffer = new byte[4096];
                                             while ((read=input.read(buffer))!=-1){
                                                        outfile.write(buffer, 0, read);
                                             outfile.close();
                                             input.close();
             }// end out while
         }catch (Exception e) {  out.flush(); }
    what is to change here thanks

  • Time stamp data write to file problem

    Hello!
    I'm just learning LabView, and have arrived at the stage of writing time-stamped data to text files.
    This seems clear enough, however when I examine the file written to disk, I find 4 unexpected characters: 3 spaces and one seemingly random number or punctuation mark, preceding every line!
    An example is:
       .2005-07-15 10:55:40.0 the value is 0.0000 cm
       .2005-07-15 10:55:40.5 the value is 1.0000 cm
    The four characters "   ." are those whose origin I can't understand. I can't seem to get rid of them.
    They seem to change with the input string, but not in a manner I can predict or understand.
    Any hints or explanations would be greatly appreciated, as I'm at wit's end after 1/2 day of puzzling over this little problem!
    Alex
    Attachments:
    time stamp data write VIs.zip ‏24 KB

    Alex,
    You found one of the subtle little things that can be frustrating to old-timers and newcomers alike. I did not recognize it until I read the help file (and I have been using LV since version 1.2).
    First, the three characters before the commas are nulls (\00).
    The reason they are there is in the help file for the Write File.vi. By wiring an array to the data input, you caused the VI to write a header telling what data format was used.
    I modified your VI to simply concatenate the strings and then write a simple string to the file. I think this may be what you were after.
    Lynn
    Attachments:
    write timestamp text line to file v3.vi ‏47 KB

  • Scanning problem. Receive error message: cannot write file. Code 10,242,7. Please help

    I just purchased and installed a Canon MX 922 multi-function printer. I'm having a problem with the scanner in that the output after scanning cannot be displayed and is accompanied with an error message : Cannot write file. Code 10,242,7. This occurs when scanning documents and images. My operating system Windows XP (32).  Can anyone please help me solve this problem? Thank you.  

    Hello. Please try the following adjustment to see if we can resolve this issue: 1.  Open the IJ Scan Utility from your Desktop or the Canon Utilities listing of the Start Menu.2.  Click Settings.3.  On the left, choose the Auto Scan tab.4.  Click the Defaults button on the lower right.5.  Continue this process with each tab on the left.6.  Click OK at the bottom of the Settings menu. Once this has been done, try scanning from the IJ Scan Utility to test the unit. If these troubleshooting steps do not work, feel free to call us at 1-800-OKCANON.

  • Xcode 3.0 & InterfaceBuilder (IB) - IB Write Files & xcode syncing problems

    Anybody tell me why IB in Leopard is broken?
    After I create a new project in xcode & then I open up the .NIB. I'll start designing my UI with custom objects. When I perform either a write file.. or Sync with xcode, it doesn't work?
    Is this a bug? If so what is the work around? Create the files in xcode first, then when performing a write files replace them???????
    Thanks,
    Jim

    Perhaps you should try to create a new project from scratch and see if that new project exhibits the same problem. If so, there is a problem with your system. If not, there is a problem with that particular project and/or NIB file. Both Xcode and the new IB work fine for me.

  • Probleme avec Imaq write file qui n'enregistre pas les images en jpg

    Bonjour,
    dans le cadre d'un stage, je suis en train de dévellopper un programme qui récupère une vidéo issue d'une caméra usb. Jusque là tout vas bien. Mais je souhaite réalisé une vidéo a partir d'une suite d'image au format jpeg que le programme aura enregistrer dans un dossier.
    Mon probleme etant que Imaq write file 2 que j'utilise n'arrive pas a enregistrer les image au format jpg (alors qu'il y arrive au forma png, tiff ou jpg2000). Ainsi, lorsque je lance la capture, le programme a l'air de faire des opération mais lorsque je vais dans le dossier où doivent etre entreposé les jpeg, celui ci est vide.
    J'utilise labview 2010 et suis sous windows 7 x64 bits.
    Merci d'avance pour l'aide que vous pourez m'apporter.

    oui bien sur, le voila :
    Pièces jointes :
    test Controle_caméra_prosilica_2.8_2121.vi ‏3752 KB
    CalculateFPS.vi ‏12 KB

  • Re: Scanning problem. Receive error message: cannot write file. Code 10,242,7. Please help

    hi. my error message is very close to this except it says 10,243,7 cannot read file instead of write file. i tried all the fixes listed here in this forum as well as just about everything else everyone else on here has listed on the net and even called canon and tried all their fixes as well to no avail. any ideas?
    [open window, place pc at edge gently tip and OOPS! crash! ]
    is anyone else getting this error message and if so; how'd you get around it?
    fixes tried:
    uninstalling
    reinstalling
    [several times]
    deleting all folders canon
    ccleaner-both the sweep and registry options with backups of course.
    sfc /scannow
    chkdsk
    thanks,
    pf

    Hi, pf!
    So that the Community can help you better, we will need to know exactly which operating system is running on your computer. That, and any other details you'd like to give will help the Community better understand your issue!
    If this is a time-sensitive matter, our US-based technical support team is standing by, ready to help 24/7 via Email at http://bit.ly/EmailCanon or by phone at 1-800-OK-CANON (1-800-652-2666) weekdays between 10 AM and 10 PM ET (7 AM to 7 PM PT).
    Thanks and have a great day!

  • Error while relocating (Can't write file (no space)) - Help please

    I have been having trouble relocating master files since upgrading to Leopard. The problem doesn't seem to affect only Aperture. I can happen when using Finder or another application to move files from one drive to another. Other types of files don't seem to be affected, just my library of image files.
    The copy operation runs for a while then hangs up. The application doing the copy reports an error that that's the end. Aperture gives this error message: Error while relocating (Can’t write file (no space)). The Finder reports plenty of available space on the destination drive!
    I remember seeing a thread--but can't find it now--about a problem with certain xmp metatdata embedded into files causing problems with file operations.
    Hoping for a solution!
    Message was edited by: thomas80205

    It's possible that you might have a corrupt file. Have you tried to copy different files on to the destination drive? If those files copy fine, then narrow down the offending file by copying less images at a time.

  • WARNING: Cannot "Read or Write" files on iPod

    My iPod has been behaving very curiosly as of late. For the past month a wanring has flashed up on my iTunes screen when attempting to sync music files. The warning says *"Cannot read the disk 'iPod'. Unable to read or write files"*. Despite this warning my iPod has been able to update daily podcasts without issue. However, when I recently purchased new music I could not get it to sync to my iPod. I have no problem listening to this new album in my iTunes library, but it just will not sync to my iPod. I created a playlist for it and attempted to add it, but I discovered that the iPod was not syncing the playlists either!
    In a recent attempt to remedy the problem I selected only to sync the playlist that had the new album. What happened was frightening. All my music was no longer on the iPod, with the exception of my podcasts! I tried altering the settings to return all the music, but now I am unable to add any of my music from the library.
    I am wondering if anyone has experienced this difficulty before, and if so, if they have any trouble shooting techniques. I have already been ti Apple's support page and completed the 5 recommended steps, to no avail. Any suggestions or thoughts as to what might be occuring.

    Luckily, backing up your itunes library is easy. Just duplicate the folder(s) with your music in it. (Most likely, it's user/Music/ITunes.) Once the copy is made, you might want to move it to a different part of your hard drive.
    Now, restoring your ipod WILL wipe the device. If there's anything on your ipod that isn't in your itunes library (unlikely but possible), you want to make sure you've got a copy of it somewhere before restoring.
    Before restoring, check to see if there is an update to the ipod's firmware that needs to be installed. This is a "longshot" but might help. Just click the "check for update" button on the ipod's "Summary" pane in itunes. (Current version is 1.2.3, I think).

  • How to write file to server side?

    hello,
    Could anyone pls help me...
    I just want to see an example how can I write to a file that is placed at the server(save place as the applet).
    p.s. I have been successfully read a file from there...
    Suppose I have signed the applet (self-signed), anymore security problem I need to pay attention to?
    Thanks a lot!!

    hi mandy, from the applet u can send the file to be written into the server to a servlet running in server and the servlet can in turn write the file into the servlet. by applet - servlet communication, u can easily read and write files to the server.

  • Cannot Write Files to my Formatted External Hard-drive

    I've been struggling with this problem for awhile now. I have a 200GB external hard drive that I used on my windows box. I have music on it and would like to use it on my macbook. When I plug it into my macbook, it mounts and shows up on the desktop. I can go into it in finder, and view the files and folders that are on it. I can also create new folders. However, when I try to read or write files to/from the hard drive, finder stalls at 'zero KB of x MB written'. If I try to copy a file to the drive, the file will be created but it will be of zero or very very small size.
    I reformatted the drive with Disk Utility and also via the command line with 'diskutil reformat /dev/disk1s5' and these reformat the drive successfully, but the same problems occur.
    What could be going on? The drive is not faulty, and it mounts just fine. I just can't read or write from the drive in OS X.
    Please help! Thank you in advance.

    The NTFS file format is not really that compatible with macs (you can only "read" files, but not "write" to them). Also, while you can reformat a hard drive with the same or different file type, the NTFS type is the only one that will not let you go from having a NTFS formatted drive and reformatting it as a different format (you can do it again as NTFS but that's it). If you have a FAT or FAT32 formatted drive, you can go and reformat it as NTFS, but once it has had the newer windows format style done to it, you can't change it to anything else.
    Also, as I think you said you could read from it at first, and then were not able to?, this would be because the reading of the files would have been fine, but as soon as you went and reformatted it again (which basically wipes the slate clean), you lost all the data that possibly was on there, and now as an NTFS format with no data, therefore nothing for a Mac to get a chance to "read", you have nothing and can only use this as an NTFS drive for windows (or any other possible OS that is NTFS compatible).
    Sorry about the bad news... Try to sell it to a windows person and get another external hard drive (formatted as FAT32 or not pre-formatted yet, then format as FAT32) so that you can use that with your Mac...

  • Enable to have the Write File to Citadel Example working

    Did somebody already run the Write File to Citadel Example with success ?
    This exemple aims at Importing Spreadsheet Data to the Citadel Database, and is given in the NI developer Zone --> Development Library --> Labview --> DSC --> Data Logging.
    I can run the exemple as described without any visible problem. But when I look at Citadel (through MAX), I can't find any trace of the data I imported (sine_wave_one for instance). According to the SampleSpreadsheet.csv I used for import, I should find a trace in the database around the 21st of march 2002...
    But I found nothing.
    Any help?
    Thanks,
    Hélène.

    I am not sure how savvy LabVIEW programmer you are, but if you feel confident you can go ahead and try to debug the code.
    The VI based servers are running on the background. You can however make the front panel visible during the execution - not the diagram. The debugging means you have to create a few indicators on the panel that will show what is going on on the diagram.
    These are the steps the enable the front panel during the execution:
    1) Open the Write File to Citadel Server VI
    2) File>>VI properties; select Window Appearance
    3) Click Customize and check the Show FP when called and Show FP when loaded
    4) Save it and relaunch the engine!
    When you start the engine again, you should get th
    e server front panel. Once you'll have some indicators on the FP you'll be able to learn more about what is going on in the VI.
    I have noticed that sometimes the example pops up with a File dialog box. I found out this was related to a race condition in the example. I am not sure if that's what you see.
    Let me know.
    Also if the example executes you should see the tag values changing - for example the string tags starts with "Row 0", "Row 1" ...
    Is that what you see?
    Dr.Tag

  • How do I read and write files on a mac?

    On my windows it's easy, but when I try to write files and read them
    on a Mac the filepath is always wrong. I want to write to my
    "Documents" folder, and when I do /Documents/Hello.txt as a filepath
    it gets it wrong. I don't know why it won't work because I'm not too familiar
    with macs yet. Any help with the filepath problem?

    Your Documents folder is not /Documents. It's /Users/your_user_name/Documents

  • Delayed Write File

    For some reason when I go to update my songs on my ipod 30gig photo it begins to download all the music and then once it looks like it is completed i get the error message that says my ipod cannot be synced the required file cannot be found. In the bottom right hand of my screen it says "Delayed write file" I went ahead and restored my ipod and redownloaded everything itunes and all and still the same problem. Somebody help!?

    Hey JasonKennedy,
    This article: http://docs.info.apple.com/article.html?artnum=304508 explains the 1418 error.
    Verify the computer has the latest version of iTunes installed and the iPod is plugged directy into a high powered USB port on the computer. If iTunes gives you the same error codes continue to steps 3&4 in the article.
    Jason

  • Applet to write file on IE4.0

    Hi all,
    Please help, the situation is like this,
    server has no support for web, no Java plugin...
    client browsers' are equipped only with IE4.0, and they will not be upgraded nor plugged with Java Plug-in.
    On these strict circumstances, how could i run an applet to read/write files?
    if the applet is converted to an application, file permission problem should be solved, but how could the clients run the CLASS/JAR files without installing JRE...
    pls help, it's in ergent. (have to finish the program in this week!!)
    Thank you a million!!!!!!
    J.

    New foundings!
    As the server is running Netware 4.2, is that possible if i just install JVM on the server and problem will be solved?
    J.

Maybe you are looking for

  • My PC won't recognize Zen Micro- please h

    I have Windows 98 on an older PC, and am planning on buying a new computer later this year. I received the Zen Micro as a Xmas gift but am just now getting around to loading songs onto it (so my free service is expired). It's supposed to be Windows 9

  • CLIENT_SEND_FAILED 500 Timeout Error

    Hi Guys, i am getting below error in PI MONI, can any one please help me how to resolve this isuue. This interface is File to Proxy(ECC). <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> - <!--  Call Adapter   --> - <SAP:Error xmlns:SAP="http

  • ATI Driver Problem - Encore CS5

    Hi All, I have spent a number of hours now trying to troubleshoot an issue with Encore CS5.  I have it installed on a HP 6930p Notebook computer with a ATI HD3400 onboard video card.  Whenever Encore starts, my screens go black and I get an error "di

  • How to repair my oracle client

    My PC have a virus "VBS.KJ", after i have kill it, my oracle client cannot connect to server, reinstall has no effect, how to repair it?

  • 1000 photos download overnight through Photo stream?

    I woke up to my iPhone 5s having downloaded 1000 photos from photo stream with no apparent reason for a change in my photo stream to cause that many old photos to upload. I logged into my Mac mini and booted iPhoto and the same 1000 photos, all were