How to create a new file - help please.

hi there
i need to create a new file in my program, i did the following:
/*code--------------------
PrintWriter out = new PrintWriter(new FileOutputStream(new File("c:\\somedirectory\\outputfile.txt")));
out.println("product code:"+productCode);
out.println("product price:"+productPrice);
out.println("product description:"+productDes);
out.flush();
out.close();
the directory c:\somedirectory\ does not exist yet. i was hoping that when the new file is created, so was the directory. when i run it. the program could not find the path with following error message:
c:\somedirectory\outputfile.txt (The system cannot find the path specified)
can anyone of you experts point a rigth solution? thank you.

thanks
so the steps to create a new file in a new directory is as follow:
//create a file object with the directory path
File d = new File("c:\\xx\\");
d.mkdir();
//then create another file object with the path and the file name
File f = new File("c:\\xx\\abc.txt");
is this right?

Similar Messages

  • How to create a new file

    hello
        how to create a new file myfile.txt in folowing URL
         http://www.mydomain.com/upload/myfile.txtregards

    the_Orient wrote:
    corrected code
    I will to create a text file on webserver
    this file hasethe content "Hello World"
    </div>
    try
    String  S="Hello World"
         URL url = new URL("http://www.mydomain.com");
         URLConnection hpCon = url.openConnection();
         hpCon.setDoOutput(true);
         File file = new File("http://www.mydomain.com/studentes/info.txt");
         file.createNewFile();
    // how to use FileOutputStream  here
    OutputStreamWriter out = new OutputStreamWriter(hpCon.getOutputStream());
         out.write(content);
         out.close();
    }catch(Exception ex){ex.printStackTrace();}     
    Exception :
    java.io.IOException: The filename, directory name, or volume label syntax is incorrect
    {code}
    regards
    Whoa! Do you know what you're doing? Do you have permission to write on that URL? Or does the pathname parameter you passed on File is correct? How about let the server-side handle the creation of file for you by just requesting it? Do you know how to create a server-side Java program (e.i. Servlet)? Umm.. There's a Java tutorial for this for you to get started: [Reading from and Writing to a URLConnection|http://java.sun.com/docs/books/tutorial/networking/urls/readingWriting.html].
    Ron
    Server-Side Development Team
    [Java-Man 2004|https://sites.google.com/site/raisoftware6/]

  • How to create a new file (doc, ppt or xls) using the secondary click??

    Is there any way to create a new file(text, doc, docx, ppt, pptx, xls or xlsx) using the the secondary click (on the desktop or any folder) just like creating a new folder using secondary click! Please do let me know!

    No. You need the Office applications to create them or another application capable of creating those types of files or at least saving files in those formats.

  • How to create a new file with existing file's resource fork?

    Hello,
    I would like to create a new file that has the resource fork of an existing file. I had though of making a copy of the existing file, seek to the beginning of the copy and write the new data, but for large files, that creates the whole file even when not needed. I currently create the new file with [NSFileManager createFileAtPath: contents: attributes:], but attributes do not include resource fork items, like custom icons, color label, etc.
    [NSURL resourceValuesForKeys] gives a common subset of resource data, like icons and color label, but that's about it. Is there some way to get the resource fork or a copy of the file without getting the whole file?
    Thanks

    What are you trying to do here? While resource forks might still be quasi-supported, you really shouldn't be thinking about them as such. Instead, think in terms of extended attributes. You can use the low-level xattr() functions to get some of that or you can use the new NSURL methods.

  • How to create a new file  having a name that is stored in a string

    Hello friends i am new to java and i need your help .
    I have a string which will take different values at run time. I want to create a file which has the same name as stored in the string . Can anyone help me?

    The Java Almanac example I linked to uses createNewFile() - the API documentation is not particularly clear about exactly what happens if c:\some\value\assigned\at doesn't already exist. But you're only a small experiment away from finding out!
    Another page gives examples of directory creation.
    http://www.exampledepot.com/egs/java.io/CreateDir.html
    Once (or if) the file is created using a File then, yes, that File is the name of the file: parent directories and all. If you create a FileReader based on the File it will read from the right place.

  • How to create a new excel file using Excel Destination when Destination file not exists.

    how to create a new excel file using Excel Destination when Destination file not exists.

    Just need to set an expression for excel connectionstring and set delay validation to true and it will create it on the fly.
    The expression should return the full path with dynamic filename in each case.
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to create a new user id in OID for Oracle Collab suite File System

    Dear Friends,
    I want to know how to create a new user id in the oracle internet directory where i can use that user for the new subscription of the oracle collabration suite file system..
    Please do the needfull and thanks in advance...
    With warm regards
    R.Prasad

    Hi!
    The way you suggest should not be used.
    A CS user will be created as a normal OID user and will receive the CS attributes in a different subtree later during the provisioning.
    For creating CS users use oesuser and uniuser. Files provisioning will work in a different manner anyway.
    cu
    Andreas

  • I had to restart my mac and couldn't remember my password and had to create a new keychain, help?? i just want to stop all these pop up screens coming up now, how do i retrieve my original password?

    i had to restart my mac and couldn't remember my password and had to create a new keychain, help?? i just want to stop all these pop up screens coming up now, how do i retrieve my original password?

    I'm not quite sure I understand what you're saying? Have you gained access to your mac, but getting pop-ups about your old password? If you have access, you could always copy important files and reinstall OS X from scratch. Also you could use the Mac as an external hard drive if you have another Mac doing the same. Those are probably the easiests ways. If it was easy to just go ahead and change passwords as so, security would be an issue. How is your computer locked? Is it a filevault password, or how much do you have access?

  • Apple loops for garageband pack doesn't show the folder content (loops, files...)  in ableton live suite 8 library browser, but I can see all the loops in the folder from finder. how can i fix this? help please.

    apple loops for garageband pack doesn't show the folder content (loops, files...)  in ableton live suite 8 library browser, but I can see all the loops in the folder from finder. how can i fix this? help please.

    Thanks Barney, I tried that but all that comes up in Spotlight are the log files that show the file paths! I don't know how Steam works. Are all the files held by Steam on their server perhaps?

  • How to create a new session in JSP file

    Usually a child IE window uses same session with parent window. Dose someone know how to create a new session when creating a new IE window by clicking a URL in parent window? The web page is writen by jsp file.

    I am not sure of your question. Are you wanting to have 2 Session objects (one for the parent window and another for the child)?
    A session is usually created once per client and is stored on the server the session id is carried around in a cookie or a URL rewrite so that everytime the user submits a page you will be able to store/access information.
    // this will create a new session object if one doesn't already exist.
    HttpServletRequest.getSession( true );
    Hope this helps

  • How do I automatically create a new file at the beginning of a new day, otherwise I only want to append that days file?

    In my robotics application I store my data using "Write to Spreadsheet.vi". I would like to append the file each time I run the program on any given day. On a NEW day I would automatically like to create a new file with a smiliar name and append that file for the day on which it is created. It's easy to do using the "Write to Measurement File. vi" but the text file created is vertical rather than horizontal, so I would like to use "Write to Spreadsheet". Any suggestions?
    Also how to I include my VI as part of this question for others to see?
    Thank you.
    Attachments:
    Untitled 4 (SubVI).vi ‏7 KB

    Does the file you are writing have a timestamp in it?  If so you could read the timestamp from the last time it was written and see if the day has changed, handling the name of the file appropriately.  The easiest way to record the timestamp is probably to write the timestamp as the number of seconds that have elapsed since 12:00 am on Firday January 1st 1904 in UT.  The "Get Date/Time in Seconds" function will give you this value.
    Message Edited by jmcbee on 03-05-2009 12:56 PM
    CLA, CLED, CTD,CPI, LabVIEW Champion
    Platinum Alliance Partner
    Senior Engineer
    Using LV 2013, 2012
    Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved.

  • Hi all, i'm new and facing a problem while creating a new file for Xcode. I can't select the box "with XIB for user interface" if the subclass is "UIViewController".this problem happen after i upgrade Xcode to 4.6 version.Appreciate for any help rendered.

    Hi all, i'm new to Mac book & Xcode. I'm learning and facing problems while creating a new file for Xcode. Before i upgrade the software, i have no issue to create simple steps in apps. After upgrade Xcode to 4.6 version, i'm facing lot's of issue eg.
    1) "the identity "iphone developer" doesn't match any valid certificate/ private key pair",
    2) can't select the box "with XIB for user interface" if the subclass is "UIViewController"..
    Appreciate for any help rendered.

    Mikko777 wrote:So what is the best?
    I wouldn't judge. I've been to Arch for a week, you know? But as said, it's VERY close to it.
    What I dislike after a week is makepkg not handling dependencies automatically (which would be overhead, so probably not appropriate).
    Mikko777 wrote:Also theres KDEmod for modular kde, dunno if its for 64 bits tho.
    Don't actually need that as said ... I see no real benefit of having that other than not beeing a KDE user or having Gentoos useflags.
    Mikko777 wrote:PS:You produce a lot of text and welcome smile
    Yeah. Wonder why I'm still employed? So do I ...

  • How do i create a new file in pdf

    I JUST STATED IN ADOBE , WOW DO I CREATE A NEW FILE IN PDF

    Hi Robert,
    Welcome!
    I see you are subscribed to our PDF Pack service.
    Check out this FAQ to help get you started!
    Let me know if this helps.
    Looking forward to hearing back from you!
    Kind regards, Stacy

  • Hi..i am trying to login i message but i cant access ,it thing i forgot my password number, please i need help,how i can reset new password number. please i need help.

    hi..i am trying to login i message but i cant access ,it thing i forgot my password number, please i need help,how i can reset new password number. please i need help.

    Go here.
    Good luck,
    Clinton

  • BB apps is not working, how to create BB email add? please help

    BB apps is not working, how to create BB email add? please help

    If none of the blackberry apps are working and you are unable to setup an email address..... have you got a Blackberry Data Plan active on your account?

Maybe you are looking for