HOw to create a text file in the given path and delete it after the use?

Hi all,
I am trying to create a text file at the given path and delete the created file after the use.
I am using following code.:
import java.io.*;
// write binary data as characters
public class RanIO {
                                        public static void main(String f[])
                                                  // First illustrate append
                                                  String lineSep = "\n";
                                                  try {
                                                                 File temp= new File("C:/Ash","cute.txt");
                                                  boolean ch=temp.createNewFile();
                                                  if(ch)
                                                       System.out.println("file created");
                                                  else
                                                  System.out.println("file Not created");
                                                  //writing to file
                                             /*     PrintWriter p = new PrintWriter(new BufferedWriter(new FileWriter("cute.txt",true)));
                                                  p.print("Emp NO");
                                                  p.close();*/
                                                            // Open fileWriter in append mode
                                                                           FileWriter fos = new FileWriter(temp, true);
                                                                           BufferedWriter bw = new BufferedWriter(fos);
                                                                           PrintWriter pw = new PrintWriter(fos);
                                                                           double d=550;
                                                                      // lineSep = System.getProperty("line.separator");
                                                                      pw.print("Hello");
                                                                      //pw.print( lineSep );
                                                                      pw.print( d );
                                                                      pw.close();
                              boolean det=temp.delete();
                                             if(det)
                                                  System.out.println("File deleted");
                                             else
                                                  System.out.println("File not deleted");
                                             } catch (IOException ioe)
                                                            System.out.println( "Append IO error:" + ioe );
My problem:
1)
I am not able to write to the file. I want to know, where i am going wrong.
It is giving error message like
"Canot resolve Symbol: temp,"
But, FileWriter Constructor should accept a File type parameter.
here temp is a file parameter.
If i am not using file=new file();
i can't delete the file after the use. i.e if i use
PrintWriter p = new PrintWriter(new BufferedWriter(new FileWriter("cute.txt",true)));
how can i delete cute.txt after the use?
2)
I am not able to write to the text file. file is created but, a blank file.
"Hello" is not written into the text file.
can anyone help me in this regard
Thanks in advance
Ashvini

Thank you Ram,
But, i want to create a text file in Append mode.
for that i used
FileWriter fos = new FileWriter(temp,true); But, it is not accepting FileWriter constructor in
this format. if i use
FileWriter fos = new
FileWriter("c:/ash/cute.txt",true); it works fine. !!!!!Here's the javadoc
public FileWriter(File file,
boolean append)
throws IOExceptionConstructs a FileWriter object given a File object. If the second argument is true, then bytes will be written to the end of the file rather than the beginning.
Parameters:
file - a File object to write to
append - if true, then bytes will be written to the end of the file rather than the beginning
Throws:
IOException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason
Since:
1.4
Are you using jdk.13 or lower ?
>
ONe more doubt, Does flush method deletes a file?
if not, then i need to use
File temp=new File("c:/ash/cute.txt");
FileWriter fos = new FileWriter(temp,true); //which
is again a problem
if(temp.delete())
out.println("File is deleted");
}I don't know whether i am taking it wrong ! or
anything wrong with my coding ! but, after creating
and writing data into a text file. I must delete it
as it contains confidential informations.
Regards,
Thanks.'flush' writes to a file immediately. Else you should explicitly call 'flush' to write contents from buffer to underlying source.
javadoc again
PrintWriter
public PrintWriter(Writer out,
boolean autoFlush)Create a new PrintWriter.
Parameters:
out - A character-output stream
autoFlush - A boolean; if true, the println, printf, or format methods will flush the output buffer
cheers,
ram.
Question; What do you gain by opening a file, writing to it and deleting it in the same program ?

Similar Messages

  • How to create a text file or XML file  and add content through  code into it...

    Hi Everyone,
    How to create a text file and add content through the code to the text file eform javascript ......orelse can we create a text file in life cycle designer...
    Else say how to create a new XML file through the code and how some content like Example "Hello World".

    You can create a text file as a file attachment (data object) using the doc.createDataObject and doc.setDataObjectContents:
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.450.html
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.528.html
    You can then export the file with the doc.exportDataObject method:
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.463.html
    This won't work with Reader if it hasn't been given the file attachment usage right with LiveCycle Reader Extensions.

  • How to creat a text file

    hello everybody
    I need your help guys in some java issue
    "surprise"
    how can I create a text file in java
    I mean I wanna check if the file is there and if its not I create it
    thanks

    > mkdirs() only creates the parent directory structure
    (may be needed as well).
    Which is what I assumed at first, based on his report of an error message. However, now I'm not so sure, based on the OP's lack of detail. I can't tell if s/he's just not handling the exception (throws or try/catch), or if s/he is actually getting a "The system cannot find the path specified" message when attempting to create a file for which the appropriate directory does not exist (as is possible with createNewFile()).
    It remains a mystery. :o)
    ~

  • How to upload a text file from a shared folder and provide an o/p

    how to upload a text file from a shared folder and provide an o/p  containing the details in each order in the text file

    Hi,
    Use <b>GUI_UPLOAD</b> to upload a text file from a shared folder.
    Use <b>GUI_DOWNLOAD</b> to download data in a file on the presentation server or use <b>OPEN DATASET, TRANSFER</b> and <b>CLOSE DATASET</b> statements to download data to the application server.
    Now, I hope the code for data fetching, if required, is already present in the report.
    Reward points if the answer is helpful.
    Regards,
    Mukul

  • Before updating my iPhone 4S, I could double click the home button, and delete all of the previously opened apps. I am not able to figure out to do that now, after installing the latest update. Does anyone know how to do this?

    BEfore updating my iPhone 4S, I could double click the home button and delete all of the previously opened apps. After updating, I am not able to figure out how to do this. Can someone tell me how to do this?  Thank you.

    After you double click the home button you swipe up on the app screenshot.

  • How to create a text file & write contents into it?

    Hi All,
    Im using Acrobat 7.0 Professional.Im writing a javascript to write a content to a text file.How can i do this using acrobat scripting objects.
    Any code snippets?
    Thanks
    myriaz

    You can create a text file as a file attachment (data object) using the doc.createDataObject and doc.setDataObjectContents:
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.450.html
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.528.html
    You can then export the file with the doc.exportDataObject method:
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.463.html
    This won't work with Reader if it hasn't been given the file attachment usage right with LiveCycle Reader Extensions.

  • How to create a text file from jsp?

    In JSP, what is the command to create a text file and dump a variable in it?

    You mean StringBuffer?

  • How to Create a text file through Portal

    Hi,
    Is there any way to create a text file(e.g Excel file) through Portal? Thanks.
    Sumita

    I have a way to do this in VBScript, I don't know if it will work with the portal but the steps are simple. If you can create a text file within portal, try to create it as an html table:
    <table>
    <tr>
    <td>Column Header 1</td>
    <td>Column Header 2</td>
    </tr>
    <tr>
    <td>Value 1</td>
    <td>Value 2</td>
    </tr>
    <tr>
    </tr>
    </table>
    When you create this file save it with XLS extension instead of TXT, create a link to it and voila! it will load Excel and you will have your data well formatted. I found this method rather better than save the file as a CSV. You can also include any html attribute inside the <TD> or <TR> like background color and font type, Excel will keep those attributes.
    I hope this will help
    Arturo

  • How to create a text file with data.

    Hi,
    I am writing java code for testing an application, some times test can failed in some cases, I want to display an error message in text file. To that I written the code as like,
    BufferedWriter bout;
    bout =new BufferedWriter(new FileWriter("test.txt"));
    String str=”Your input data is not match with pattern”
    bout.write(str);but here it is creating a text file “ test” without any data in it.
    Can any body help that to execute the program properly
    Regards
    Buntty

    sabre150 wrote:
    JoachimSauer wrote:
    You didn't close your BufferedWriter. Since it's buffered it probably didn't write anything to the underlying file.
    Generally you must close every Writer/OutputStream that you no longer use or it won't be written reliably.It's not quite as simple as that. If you have a chain of Writers / OutputStreams then you only have to close() the outer most one since each is responsible for closing any Writer/OutputStream that it wraps. If you do decide to close them individually (a bad idea but people do do it) then you MUST close them starting from the outer most one and working to the most inner one or you will not guarantee to flush any buffered content.Of course. I might have used a misleading phrasing here. What I meant is "Every time you are done with a Writer, you must close it" and not "You must close *every* Writer that you used". Thanks for the clarification.

  • How to create a par file that includes an image and a .swf file

    Hi everyone,
    I have a requirement to create a <b>.par file which will contain a .swf file and a .gif file</b>.
    Can anyone please tell me the steps to do so.
    Thanks in advance

    Thanks Ranjeet for the quick reply.
    I have created a portal project and placed the .swf file and the .gif file in the images folder and deployed it to the server. I downloaded the .par file and chked that it contained the .swf and .gif files. But when i run the application it <b>does not show me the .swf file</b> . An icon with a cross mark appears instead. I have flash player installed on my PC .The .gif file when run works fine but not the .swf file.
    Can anyone tell me a workaround for this ?

  • How to create empty text file on target system for empty source text file

    Hi All,
    I have an issue in handling empty file in the Text (FCC) to Text (FCC) file scenario. Interface picks text file and delivers on target system as text file. I have used FCC in both sender and receiver CCs.
    Interface is working fine if the source file is not empty. If the source text file is empty (zero Bytes), interface has to delivery an empty text file on target system.  I have setup empty file handling options correctly on both CCs.
    But when I tried with an empty file I am getting the error message 'Parsing an empty source. Root element expected!'.
    Could you please suggest me what I need to do to create an empty text file on target system from empty source text file?
    Thanks in Advance....
    Regards
    Sreeni

    >
    Sreenivasulu Reddy jonnavarapu wrote:
    > Hi All,
    >
    > I have an issue in handling empty file in the Text (FCC) to Text (FCC) file scenario. Interface picks text file and delivers on target system as text file. I have used FCC in both sender and receiver CCs.
    > Interface is working fine if the source file is not empty. If the source text file is empty (zero Bytes), interface has to delivery an empty text file on target system.  I have setup empty file handling options correctly on both CCs.
    >
    > But when I tried with an empty file I am getting the error message 'Parsing an empty source. Root element expected!'.
    >
    > Could you please suggest me what I need to do to create an empty text file on target system from empty source text file?
    >
    > Thanks in Advance....
    >
    > Regards
    > Sreeni
    the problem is that when there is an empty file there is no XML for parsing available. Hence in case you are using a mapping it will fail.
    What ideally you should do is to have a module that will check if the file is empty and if so write out an XML as you want with no values in the content/fields.
    Or the next choice would be to have a java mapping to handle this requirement. I guess that on an empty file the java mapping will go to an exception which you can handle to write out your logic/processing

  • How to create a txt file, load it, modify it and then save it again?

    Hello everyone!
    I have a question and I hope you'll help me.
    I'd like to create a txt file (please see attached pdf file) but I don't know how. I've tried many methods but it's not working 
    The user should be able to change the parameters (for example "Time", "Time Type" ...etc) and the corresponding values from the Front Panel.
    The number of section (Begin Line......End Line)  is 128.  Means, the final file should contain  "Begin Line1....End Line1"   till  "Begin Line128....End Line128".
    Please, take a look at the attached file to see how does the structure of the file look like.
    Note:  the seperator between a parameter (example, "Time") and its value (example, "7" in the section "Begin Line1....End Line1") is a colon( " : " ) and not an equal (" = ").
    Thank you very much for your help.
    Best regards
    Attachments:
    Batch File.pdf ‏8 KB

    Hi
    thanks for your answers.
    I'm using LV 8.2  and my file should be saved in txt.
    Initially the file doesn't exist. So, the user choose the parameters and their values from the Front Panel
    and then hit a button to create that file. The user should be able to reload (Front Panel button) the created file, modify it or not and then resave it.
    Before hitting the "create file" button the user define (on the Front Panel)  the number of sections ("Begin Line.....End Line") to be created.
    I joined a VI here just to explain the idea. May be that can help you to help me.
    I appreciate yoyur help!
    Kabanga
    Attachments:
    Create batch file.vi ‏14 KB

  • ITunes changing the ID3 tags and deleting music after syncing or opening

    After syncing (or opening iTunes), iTunes changes the tags in about 25% of my music (this time it was about 90% affected). It removes the total track number on some of the songs. This has been a consistent problem. I noticed that it also actually erased some of my music, random tracks in my library are now missing (gone in windows explorer also). I have reformatted my iPod and restored it, it's not that. What is going on!! Going through and fixing 7500 songs every time I sync is ******* me off
    Here is a picture of what it is doing: removing the total track on some songs
    http://i169.photobucket.com/albums/u233/jupiterssj4/itunes.jpg
    Forgot to mention that it also copied the artist field data to the album artist field... had to erase all of those too

    Mine is doing the exact same thing. It happens every time I click on a song. Weird letter-number strings are inserted into the Comments field, my album art is gone, and the track numbers are messed up.
    I've tried upgrading to the new iTunes. I tried reinstalling iTunes. I turned off my soundcheck option and deleting potentially comprised files. Nothing's worked.
    I've tried emailing Apple directly and got no help. Anyone know what's going on???
    http://photos.walmart.com/slideshow/AlbumID=46480802/PictureID=1343518875/a=9835 065_9835065/otsc=SHR/otsi=SPIClink

  • How to create an XML file from a given EDI file?

    Hi All,
    I am trying to write some BPEL processes that will be sending EDI Documents to Integration B2B using the AQs.
    BPEL works with XML data and finally enqueues it to the AQ IP_OUT_QUEUE. From there B2B will pick up and send to Trading partner. I have sample EDI documents but they are not xml. Can anyone tell me if i can convert these EDI docs to XML?
    Can the EDIFECS builder be of any use here?
    TIA,

    B2B adapter? I just want some test data. Finally the setup is going to be such that some xml is going to be posted to the B2B internal channel and then on it will translate and send to Trading Partner.

  • How to create folder if not exist in given path.

    Hi Friends,
    I am developing file upload utility,
    i want to keep the uploaded files in c:/company/upload/A
    when i launch application on another pc where there is no structure like this ..
    how it will create automatically and how to check through
    file.exists() ?
    please help.

    when i launch application on another pc where there is no structure like this ..
    how it will create automatically and how to check throughThe File method mkdirs() {color:#3333FF}"Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories."{color}
    http://java.sun.com/javase/6/docs/api/java/io/File.html#mkdirs()

Maybe you are looking for

  • Flash working on some computers - but not others

    Good afternoon, We had a third party flash developer build out the flash navigation and masthead videos for a client's web site and although it works fine on my computer (and on the developer's computer), it does not work on any of the client's compu

  • Help with exporting. Video looks horrible after export, but great when in premiere pro

    Hey guys, looking for some advice on exporting. When I finish a video, the color and everything looks great while in premiere pro, but after exporting it, the color ends up looking dull and the whole video looks blurry.  I'm filming with a canon vixi

  • Warning message in method

    Is it possible insert a warning message in a method? If it is possible canyou send me an example? Thanks a lot. CV

  • Settling Freight Costs

    Gurus u2013 see below regarding SAP shipment cost document (SCD) and the associated Service PO.  Any thoughts on how to correct this? CASE: u2022     Create SCD with reference to shipment number. This SCD creates a Service purchase order and a Servic

  • Copying results in Calculator to clipboard. How?

    I'm assuming that we should be able to copy the results from a calculation on the Dashboard widget Calculator to the clipboard to paste back into a document. The Command C does not seem to work. How is it done?