I need a help to generate new file

Hi Guys
I need your help. I have two text box in my form, the first one takes the file name to read, and then when user type in another file name in the second textbox, result should be saved as a typed file name in the same path.
What I really want to do is, when the file is exist already (for instance, I'll name it as result.txt), my program scan through the result.txt file and append the new data at the end of the file. But result.txt file doesn't exist, it has to generate new file and save the data into the new one. I think I need to implement these in the OpenFile1() function, but I dont' know how.
Does anybody have idea to solve this?
private void saveFile() {
textArea.append("SAVE FILE\n---------\n");
if (openFile1())
     try {
          outputToFile();
catch (IOException ioException) {
          JOptionPane.showMessageDialog(this,"Error Writing to File",
               "Error",JOptionPane.ERROR_MESSAGE);
private boolean openFile1 ()
     // Display file dialog box
title=textfield1.getext();
path=fileName_in.getPath();
     File file_out = new File(path, title);
if (fileName_out == null || 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(true)
fileOutput = new PrintWriter(new FileWriter(fileName_out));
return(true);
else
catch (IOException exc) {
System.err.println("# Error: " );
private void outputToFile() throws IOException
// Initial output
     textArea.append("File name = " + fileName_out + "\n");
     //process();
     // Test if data exists
     if (data != null)
     Date now = new Date();
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
String s = df.format(now);
//long nowlong=now.getTime();
fileOutput.println(s);
fileOutput.print(fileName_in.getName() +" of slope value:" + slope);
textArea.append("File output complete\n\n");
     else
textArea.append("No data\n\n");
     // End by closing file
     fileOutput.close();
Thank you so much!

There's a lot of unnecessary code there, and anyway it isn't formatted in a readable way so I am not going to look too closely at it. But if you want to append to the file if it already exists and create the file if it doesn't, then all you need is this: fileOutput = new PrintWriter(new FileWriter(fileName_out, true));Note the "true" parameter there which (if you look in the API documentation) says that new data will be appended at the end of the file.

Similar Messages

  • I need a help in reading video file of 80MB into ...

    Hello,
    I need a help in reading video file of 80MB into a vector storing ByteArrays in it.Please help me soon.
    Thank You

    Hello,
    I was able to solve my problem by thinking & my code goes as follows.I am trying to read a video file in my program.
    public Vector getFileMediaContent(RandomAccessFile fileObj){
         Runtime runtime = Runtime.getRuntime();
    System.out.println ("Free memory : inside Boolean Type Panel" + runtime.freeMemory() );
    dataContent.removeAllElements();
    System.out.println("dataContent :"+dataContent.size());
    try{
    int size=(int)fileObj.length();
    if(size<2000000){
    byte[] data = new byte[size];
    fileObj.read(data);
    dataContent.addElement(data);
    data=null;
    System.gc();
    else{
    int fixedsize=2000000;
    int startindex=0;
    int read=0;
    int remaining=0;
    while(read!=-1){
    byte[] data=new byte[fixedsize];
    read=fileObj.read(data,0,data.length);
    dataContent.addElement(data);
    startindex=startindex+data.length;
    remaining=size-startindex;
    fileObj.seek(startindex);
    data=null;
    System.gc();
    if(remaining>0 && remaining<2000000){
    byte[] data1=new byte[remaining];
    read=fileObj.read(data1,0,data1.length);
    dataContent.addElement(data1);
    data1=null;
    System.gc();
    System.out.println("outside while");
    System.out.println("dataContent 1 :"+dataContent.size());
    System.out.println ("Free memory : inside Boolean Type Panel" + runtime.freeMemory() );
    fileObj = null;
    System.gc();
    }catch(Exception e){
    e.printStackTrace();
    return dataContent;
    Now I am not facing the problem of IndexOut of Bounds Exception But I am getting Out of Memory Error.
    Can You suggest me to come out of this,.
    As I know I have two solutions.
    1.Make the objects Null which is using more space & call System.gc();
    2.Increase the Virtual Memory of my System.
    Any solutions other than this?
    And How to Increase the Virtual Memory?Please do reply.
    ThankYou

  • Need Your Help with Swapping SWF files

    Hello,
    I am need to swap Two SWF files. I am acheving this by make
    one swf as a holder. call it main.fla main.swf file. Embed that
    file into my html document. In that file I placed one button with
    the
    following action :
    on (release) {
    loadMovieNum("second.swf", 1);
    in that file have a button with action to load the 3rd file :
    on (release) {
    loadMovieNum("3rd.swf", 1);
    by loading them in same level (1) they will replace each
    other. My problem is that my SWF files obtain some information
    using combination of PHP and XML file. I have noticed when I place
    the SWF with it’s required PHP and XML in separate folders
    the SWF file is uploaded (swapped) but since the PHP files are NOT
    run by the server my dynamically generated XML files are empty and
    therefore the uploaded SWF file has not information expect the SWF
    file. Is there any way to get round this problem?
    Thank you in advance for your help and hope you have a great
    day.
    Cheers,
    Babak

    Khoramdin wrote:
    > Hello,
    >
    > I have two separate Flash SWF files which I would like
    upload into the same
    > HTML file. But I would like to load only one of them at
    the time and would
    > like to have a Button on each SWF Flash file which
    causes the other SWF to be
    > loaded.
    >
    > hmmm.. I am not sure if I managed to make sense. :o) Let
    me try it one more
    > time. :o) I would like to swap one SWF file for another
    SWF file by clicking
    > on the buttons which are placed on the SWF files! :o)
    make one swf as a holder. call it main.fla main.swf file.
    Embed that file in your html document. In that file place
    button with the
    following action :
    on (release) {
    loadMovieNum("second.swf", 1);
    in that file have a button with action to load the 3rd file :
    on (release) {
    loadMovieNum("3rd.swf", 1);
    by loading them in same level (1) they will replace each
    other.
    Pretty simple..uh ?
    Regards
    Urami
    Happy New Year guys - all the best there is in the 2006 :)
    <urami>
    http://www.Flashfugitive.com
    </urami>
    <web junk free>
    http://www.firefox.com
    </web junk free>

  • Need urgent help to generate SPL Data Sources for Line Items

    Hi All,
    I am trying to extract the Special Purpose Ledger Data from R/3 into BW. To do this, I am following the steps to generate the Data Sources for Totals table and Lien Items Table.
    Using Transaction BW01 and BW03 on the R/3 side, I am able to generate the Totals Record-DataSource   successfully.
    But I am not able to generate the Line Items-DataSource. I am using the same procedure.
    Can someone please help me or point me in the right direction. Are there any other settings I need to make to generate the Line Items-DataSource. Interestingly, I am able to generate the Line Items-DataSource  for some other old ledgers in the System like ZZ and ZX. But I need the Line Items-DataSource  from a ledger called ZP for which I am having trouble.
    I would greatly appreciate if someone can get back to me ASAP.

    During BW01, The Generate extract structure is fine for both Total and Line Item Table.The issue is when we run tcode bw03 where you assign the datasource to a ledger.
    Here, I can assign only for the Total Records data source and NOT for the Line Items-DataSource.
    I hope I could explain the issue. Looking forward for some advice.

  • Need urgent help with creating .war file ...

    My boss gave me one day to create an app. that runs on Apache Tomcat 4.0.6. I managed to get it done, but now I'm trying to move it from my machine to the web server. Each time I try to create a .war file I get an error saying "no such file or directory". Am I missing a step here??
    What I do is: go to the webapps/<appname> directory where the app. is located, type in jar cvf * path/to/application/appname.war.
    I then get the "no such file..." message, then a message that says "added manifest" then lines on the screen that say adding: blah blah file. It goes through all the files in my app directory but I get no resulting .war file.
    I'm so frustrated and confused at this point, any help would be greatly appreciated.

    >
    What I do is: go to the webapps/<appname> directory
    where the app. is located, type in jar cvf *
    path/to/application/appname.war. No need to create an intermediate zip file, or to use JDeveloper to create a simple war file.
    You just need to put the WAR name before the list of files.
    jar cvf appName.war *

  • Need a help to generate online html code

    I need a help with html code. I my page user in the tet area inserting a plain text and i am using servlet put it to DB, but now we need to use not plane text. Need to use custom text like <font color=121245>hello</font> <font color=457898> nice day</font>

    but now we need to use not plane text.Who is we?
    Need to use custom text like <font color=121245>hello</font> <font color=457898> nice day</font>Have you tried anything yet?
    What aspect of this requirement is tripping you up?

  • I need some help with my new podcast. Please!

    I've just set up a new podcast and it's online on itunes. The xml file is hosted on my website. Can i edit the text within this file...i.e. if there is a spelling mistake...ping this...and itunes will update it? Cos i tried doing that but no changes were made...any ideas?
    Also, to generate my xml file, i used this website
    http://www.podcastblaster.com/podcast-feed/index.php
    However i noticed that feedburner allows you to collate statistics on subscribers and podcast downloads....how can i switch to feedburner? i find this all so confusing. does anyone know what im talking about?

    From looking at their site, Podblaster creates the feed file from the data you give it: so it's no good you editing the feed file yourself as Podblaster will over-write it the next time you add an episode. Any changes you make to data or episode in Podblaster will cause an amended version of the feed file to be uploaded and this will eventually be reflected in the itunes Store; it usually takes 1-2 days, occasionally longer, for new episodes to appear in the Store, and it's possible that minor amendments to the texts won't show until you upload a new episode.
    To take advantage of Feedburner's statistics facilities you need to submit the feed to Feedburner, and then submit the feed it generates to the iTunes Store. This will involve you either using the procedure detailed here (which involves adding a special tag to the feed - something you may well not be able to do) or submitting this feed as a new podcast to the Store (which will necessitate making a small change to the name).
    If you have any further queries please post both the URL of your feed and of the iTunes Store page (please include the http:// in both cases), without which it's possible only to give very general answers.

  • Increment values within XML document and generate new file

    Good day Gurus of the Java World,
    I have a XML file and would like to generate a 100 unique files of this one file.
    The tags that need to be unique are UniqueID (alpha numeric field), TranAmount (numeric filed) and RefNumber (alpha numeric field).
    The rest of the tags can remain as is.
    How do I go about doing this? Please assist.
    <Payment>
    <UniqueID>48a6bd92-19c8-11e2-a2ba-000000000000</UniqueID>
    <EffectiveDate>20121018</EffectiveDate>
    <TranCode>1000</TranCode>
    <TranAmount>000000000123456</TranAmount>
    <TranDate>20121018</TranDate>
    <TranTime>014532</TranTime>
    <Check></Check>
    <DrCrInd>CR</DrCrInd>
    <Name>ABC</Name>
    <BrCode>1234</BrCode>
    <RefNumber>SALARYWAGE</RefNumber>
    <AccNumber>123456789</AccNumber>
    <BackoutCount>0</BackoutCount>
    </Payment>

    1. Parse the document into a DOM.
    2. Modify the nodes which you said you wanted modified.
    3. Serialize the DOM to a new document.
    4. Repeat steps 2 and 3 as required.

  • Need some Help with the new Genius Mixes on iTunes 9

    I would like to know how to use the New Genius Mixes on iTunes 9. I don't quit know how to use it yet and like all of us we're all just learning how to use the Genius Mixes. I did watch the KeyNote but they didn't go into great detail on how to use it. Does Apple have a web site that has more detail instruction on how to use the genius Mixes? I did find some info. on how to use the Genius mixes but it didn't go into great detail on how or what to do with the genius Mixex and thats what I need.
    when I click on the genius Mixes icon under the "Genius", what shows up is a Big square with four album images of my music that I have in my music collection, I go and roll my mouse over the Big square with my four music albums and click on it to play the music and it'll play what ever I have in the Genius Mix list plus as I roll my mouse over the Big Square, under it it says "Jazz Mix" with some text writings under the Jazz mix.
    I want to change the Jazz mix Title and I want to know how to add more music square boxes to my Genius Mixes just like they show in the Keynote and I would like to edit and create my own four square music boxes in my Genius Mixes.
    I never used my music genius list, I always created just a play List, now I am just learning how to use this music Genius lists and I don't know how to use it at all and I need someone that knows how to use thr Genius Mixes list to help me how to use it since there isn't a how to book yet for the new iTunes 9.
    Can someone Please help me with the new genius Mixes on iTunes.
    Thank you,
    Mrs Trisha Foster

    Today, I was getting an array out of bounds exception on a split
    I don't see how that could happen with the 'split' method since it creates its own array.
    For this particular string, ordSplit.length = 24 and commas = 26.
    PERFECT! That is exactly what it should be!
    Look closely at the end of the sample string you posted and you will see that it has trailing empty strings at the end: '1096200000000242505,,,'
    Then if you read the Javadocs for the 'split' method you will find that those will NOT be included in the resulting array:
    http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#split(java.lang.String)
    split
    public String[] split(String regex)
    Splits this string around matches of the given regular expression.  This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array.
    Just a hunch but your 'out of bounds exception' is likely due to your code assuming that there will be 26 entries in the array and there are really only 24.

  • Need a help in j2me-send file to a bluetooth address(mobile to mobile)

    Dear All;
    I am new in J2ME programing...
    I have an application, in which i want to send a copy of my application (application.jar) to other bluetooth enabled mobiles.
    I have code for searching and listing other bluetooth mobiles.
    i want to send file to this bluetooth address..i have the address..
    Please help me if anybody can..
    It is so urgent..

    Siyampa, don't multipost. I've deleted your other threads.

  • Need to Remove Auto-generated Batch File

    I inherited a RoboHelp 7 project. When I generate the primary layout of this project, it automatically generates a folder called !SSL! with another folder inside it called franksTest. Needless to say, it doesn't look v. professional to have a folder called franksTest as part of the final project that goes with the software product. I have no use for either of these folders, but I don't know how to permanently remove them, particularly franksTest, from the generated project.
    Anyone have any ideas for me? Thanks!

    Hi there
    When you generate a layout, as you have seen, the layout follows suit with what the Single Source Layout name is. So you may see a different response by creating a new layout and naming it appropriately.
    Additionally, all the files inside the folder should work independently of the actual folder name. So even if you didn't know you could rename the layout, you could rename the folder without issues.
    Cheers... Rick
    Click here for Adobe Authorized Captivate and RoboHelp HTML Training
    Click here for the SorcerStone Blog
    Click here for RoboHelp and Captivate eBooks

  • *Need Immediate Help*: Aperture Olympus Raw Files

    I need help, is there a way to open Olympus Raw Files (.orf) in Aperture? I really need to get my camera's raw photos working!
    -Thanks

    There are a number of cameras that either were once supported by iPhoto or Aperture and now are not, or that are not supported yet. Apple support declined to provide a list of cameras iPhoto and Aperture were compatible with.
    If you use a Canon Digital Rebel, you'll be okay. Otherwise test the software with your camera before buying one or the other.
    If all else fails, Adobe Lightroom will, as far as I know, open any RAW image from any camera once it's converted to DNG-RAW with the free DNG converter. So, if you can't get RAW to work with Aperture or iPhoto, there is an alternative.
    iPhoto and Aperture are the only photo apps I've tried that will not import RAW of any kind from my Nikon 5700. Apple support had no fix.
    If anyone has one, I'd love to hear it.

  • Need your Help with Swapping SWF File Problem

    Hello,
    I have two separate Flash SWF files which I would like upload
    into the same HTML file. But I would like to load only one of them
    at the time and would like to have a Button on each SWF Flash file
    which causes the other SWF to be loaded.
    hmmm.. I am not sure if I managed to make sense. :o) Let me
    try it one more time. :o) I would like to swap one SWF file for
    another SWF file by clicking on the buttons which are placed on the
    SWF files! :o)
    I was wondering if that is possible or I should think of
    another way to get around this problem of mine.
    Thank you very much for your help and have a great day.
    Cheers,
    Babak

    Khoramdin wrote:
    > Hello,
    >
    > I have two separate Flash SWF files which I would like
    upload into the same
    > HTML file. But I would like to load only one of them at
    the time and would
    > like to have a Button on each SWF Flash file which
    causes the other SWF to be
    > loaded.
    >
    > hmmm.. I am not sure if I managed to make sense. :o) Let
    me try it one more
    > time. :o) I would like to swap one SWF file for another
    SWF file by clicking
    > on the buttons which are placed on the SWF files! :o)
    make one swf as a holder. call it main.fla main.swf file.
    Embed that file in your html document. In that file place
    button with the
    following action :
    on (release) {
    loadMovieNum("second.swf", 1);
    in that file have a button with action to load the 3rd file :
    on (release) {
    loadMovieNum("3rd.swf", 1);
    by loading them in same level (1) they will replace each
    other.
    Pretty simple..uh ?
    Regards
    Urami
    Happy New Year guys - all the best there is in the 2006 :)
    <urami>
    http://www.Flashfugitive.com
    </urami>
    <web junk free>
    http://www.firefox.com
    </web junk free>

  • Need urgent help with service and file removal

    Hi,
    I need a powershell script that would stop a windows service ,wait for 2 mins, delete a particular file from C:\documents&settings and then start the service again.Is this possible ?
    Thanks

    Thanks for the reply chen. May be i was not clear in my query
    I plan this because a particular file of configmgr is corrupt on workstations. So the service has to be stopped first before the deletion. I need to run this on many computers remotely. The import file will have the machines that need the script to be run.
    The script has to run all the four steps on the machines based on the import file and export to a file with the results.How can i modify ?
    The sequence will be as follows
    Stop-Service -Name BITS -Verbose
    Start-Sleep -Seconds 120
    Remove-Item -Path C:\documents&settings\***** -Force -Verbose
    Start-Service -Name BITS -Verbose
    Regards
    Sd

  • Need urgent help with a new Z program please

    I have to write a program that finds files matching some pattern, for example I have files test1,test2,test3 in a directory then if I pass test* as parameter it should find all the files i.e, test1,2,3. I have to then store the files in internal table, loop through it and have to call some other program zzz that has a selection screen with default parameters.
    1) Is there any function that I can call that gives all the files by passing wild card (ex:test*) and store the files in internal table?
    2) How do I call some other program ZZZ from my program?
    3) How do I pass values from my program to other program's selection screen?
    Your help would be greatly appreciated.
    Thanks.
    Mithun

    Hi,
    1) data: FILE_TABLE TYPE STANDARD TABLE OF FILE_INFO.
    data: wa_file type file_info.
    data: count type i.
    CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_LIST_FILES
                EXPORTING
                    DIRECTORY = 'C:\'
                    FILTER    = 'test.*'
                    files_only = 'X'
                changing
                    FILE_TABLE = file_table[]
                    count      = count.
    loop at file_table into wa_file.
      write: / wa_file-filename.
    endloop.
    2) You can use SUBMIT statement to call another program..
    3) In the SUBMIT statement you can use the WITH addition to pass the values to the program.
    Thanks,
    Naren

Maybe you are looking for