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.

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 - 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?

  • 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 PDF with a variable name

    I am a new user and i need a suggestion.
    I need to create a PDF file with a name that is a variable.
    I extract some data from SAP and i want use the "Offer number" to call my file.
    Wher i have to past my "variable" to the OutputFileName?
    Thanks
    Jeix

    This isn't an Output Designer question but an Output Server question. Anyway, see the subject titled "Dynamic pdf filename creation from form data content", currently about 13 subjects before yours.
    http://www.adobeforums.com/webx/.59b585c2/0

  • 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.

  • 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

  • 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 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

  • How can I interactively create a New File in LabVIEW 2011?

    I am trying to create a new binary file interactively in LabVIEW, but the File Path control only offers the ability to either type in the full path and file name (cumbersome for the user), or browse for an existing file. I want to open a "New File" dialog that will allow the user to browse to the target directory, then be able to enter the name of a non-existing file to save the data to.
    The way I'm currently doing it is creating a TXT file using the Windows Explorer "New Text Document" pop-up, then changing the file extension to the new value...which is again, very cumbersome.
    The only thing I've found online is that there used to be a "New File.VI" in an older version of LabVIEW apparently...but I can't seem to find it in 2011.
    Solved!
    Go to Solution.

    You can create a new file using the browse button.
    Did your right click on the file path control and check the settings in the "Browse Options" menu?

  • How to create a new partion in my HP (Compaq LE1902x )PC that has already 4 primary partitions ?

    How to create a new partion (to save my files & Folders) in my HP (Compaq LE1902x )PC that has already 4 primary partitions ? when something goes wrong along with OS(C) drive my all files are lost. so i want to create a new partition & dedicate it to my files & folders.

    I would consider another problem. What if the hard drive (not the OS) fails. You'd lose all your data, all partitions. It seems better logic would be to copy your files and folders to either an external hard drive or USB thumb drive.
    I would not use the internal backup program, but would manually copy the data. I also would not leave such device attached to the computer.
    In my system I have a separate USB thumb drive that stored critical medical and legal documents. That way, I can travel with it, as needed. I also clone my primary desktop every 30-45 days. That way, if I get a failure, it's only that far back on lesser files.
    I am a volunteer. I am not an HP employee.
    To say THANK YOU, press the "thumbs up symbol" to render a KUDO. Please click Accept as Solution, if your problem is solved. You can render both Solution and KUDO.
    The Law of Effect states that positive reinforcement increases the probability of a behavior being repeated. (B.F.Skinner). You toss me KUDO and/or Solution, and I perform better.
    (2) HP DV7t i7 3160QM 2.3Ghz 8GB
    HP m9200t E8400,Win7 Pro 32 bit. 4GB RAM, ASUS 550Ti 2GB, Rosewill 630W. 1T HD SATA 3Gb/s
    Custom Asus P8P67, I7-2600k, 16GB RAM, WIN7 Pro 64bit, EVGA GTX660 2GB, 750W OCZ, 1T HD SATA 6Gb/s
    Custom Asus P8Z77, I7-3770k, 16GB RAM, WIN7 Pro 64bit, EVGA GTX670 2GB, 750W OCZ, 1T HD SATA 6Gb/s
    Both Customs use Rosewill Blackhawk case.
    Printer -- HP OfficeJet Pro 8600 Plus

  • How to create a CSV file in java

    how to create a CSV file in java

    this is the code that I have used in a hp project:
    private static final String DELIMIT = ",";
    StringBuffer buf = new StringBuffer();
    public void addString(String str){
    buf.append(toEscapedStringLiteral(str.replaceAll(" ","").trim())).append(DELIMIT);
    public void sendFile( String strData ,
                                String strTitle,
                                String strContType,
                                HttpServletResponse res ) throws IOException {
              byte[] _filedata=strData.getBytes();
              res.setContentType( strContType );
              res.setHeader( "Content-Disposition", "attachment;filename="+ strTitle );     
                     DataOutputStream out = new DataOutputStream( res.getOutputStream() );
              out.write( _filedata, 0, _filedata.length );
              out.close();
    public void addStringWhithReturn(String str){
              buf.append(toEscapedStringLiteral(str.replaceAll(" ","").trim()));
              buf.append( "\n" );
    private String toEscapedStringLiteral( String charSeq ) {
              if ( null == charSeq ) {
                   charSeq = "";
              return "\"" + charSeq + "\"";
    ....hope its help
    kou

  • How to create a new account and copy all settings?

    I think my main user account is corrupted. So I want to create a new account and copy all of my settings, files etc..and more than likely piecemeal just incase my settings are what is corrupted. That way I can isolate the problem.
    I don't plan to delete the main account until satisfied and I also have my Time Machine backup plus my SuperDuper backup.
    I can/should be able to figure out how to create the new account, but I am very unclear on the best/easiest approach to copy in my iTunes files and settings, applications(is this even an issue), address book, email, etc? I should be able to find most everything underneath my home account folders but what else am I missing here? I don't want to find out the hard way.
    Please share some advice or perhaps a link/FAQ on how to approach.
    Thanks in advance.
    --Mickey

    use this [link|http://discussions.apple.com/message.jspa?messageID=6185507].

Maybe you are looking for

  • Disk utility not responding

    Hello. I've got a MacBook Pro which my daughter turned off and on badly resulting in a grey screen.  Followed instructions for that issue and have got to installing the disc utility DVD which came with the mac.  Clicked on the hard drive and then 'fi

  • How to activate both connected monitor

    In my application, i have to connect 2monitors with the CPU and have to activate both connected monitors(means both should show windows) PRASHANT SONI SOFTWARE ENGINEER-LabVIEW

  • Auto-Managed forms and DbDataSource.Offset

    I have defined a custom form that navigates a list of UDO's. However, when I navigate the objects using the 1st/prev/next/last button, the bound fields do change as expected, but DBDatasource.Offset still is set to 0! Is there a way to correctly rese

  • How Can I set Specific RingTone for one person and general ringtone for all?

    Hello All, I have a problem with ringtone. I want to set specific ringtone for manager in my 99 series ip phone. Customer needs to know when manager calls him, that is why he told me that he wants to set specific ringtone for Manager. Thanks a lot Ba

  • Connecting to a 2007 vehicle

    My parents just got a new ford truck that has a plug in for mp3 players, i'm just not sure what I need to get to plug it in. It looks like a plug in you use for head phones. Anyone have any ideas?