Read a text file then write it with the same name

Hello
I have to read a file (.cvs file) then change a value of a field in it and save it again. Therefore, the read file and the write file is the same name. I use CVSParse for doing this
Here is my code:
private void updateClassName(String className, String fileName) throws IOException{
          String[][] values=new String[0][0];
          FileReader fileReader = new FileReader(fileName);
     BufferedReader in = new BufferedReader(fileReader);
          values = CSVParser.parse(in);
          List lines = new ArrayList();
          for (int i=0; i<values.length; i++){
               values[2]= className;
               lines.add(values[i]);
          try{
               CSVPrinter cp=new CSVPrinter(new FileOutputStream(fileName));
               Iterator i=lines.iterator();
               while (i.hasNext()){
                         String[] line=(String[]) i.next();
     cp.writeln(line);
     cp.close();
     catch (IOException e)
     logger.error(e.getStackTrace());
     logger.info("ERRORS: CANNOT WRITE INTO FILE");
It it OK when the read file and the write name is the same?
It is OK with the code above?
Many thanks
sho

Sorry
I post the code again:
<code>
private void updateClassName(String className, String fileName) throws IOException{
String[][] values=new String[0][0];
FileReader fileReader = new FileReader(fileName);
BufferedReader in = new BufferedReader(fileReader);
values = CSVParser.parse(in);
List lines = new ArrayList();
for (int i=0; i<values.length; i++){
values[2]= className;
lines.add(values);
try{
CSVPrinter cp=new CSVPrinter(new FileOutputStream(fileName));
Iterator i=lines.iterator();
while (i.hasNext()){
String[] line=(String[]) i.next();
cp.writeln(line);
cp.close();
catch (IOException e){
</code>
I have indent but it does not display correctly. I donot know why
Thank you, jverd, for very good strategy. That is what I need

Similar Messages

  • My goal: "convert into pdf" -- the file is instantly saved with the same name as pdf. feasible?

    Good evening dear experts,
    i use Adobe Acrobat 9 pro extend to convert word, ppt, jepgs etc. into pdfs.
    No if i
    1) convert a ppt into a pdf: it asks --> "save as" --> converts --> opens the file
    2) convert a jpeg into a pdf: it instantly --> opens the file as pdf --> i need to save it manual under "save as"
    In both cases i want to
    my goal: "convert into pdf" --> the file is instantly saved with the same name as pdf
    WITHOUT asking me "save as" + "opening of the file".
    Is the possible, and if yes, HOW ?
    A fast answer is very very much appreciated, for i have to convert hundreds of files tonight in order to get it into 1 pdf
    Thx and greetings from Germany,
    Julia

    We are nearly there!
    A] - righclick "convert-to-method": @Bill: thx again, your approach worked for ppt, doc-files etc.
    2 problems:
    1) exception: for jpegs/bmps it doesn't work (the file is still opened after conversion, strange).
    2) the output-folder. it only accepts the standard "output-folder documents/*.pdf" (which is a step further but not my end-goal). If i choose another output-folder via "browse", this setting is NOT SAVED (even after clicking on "accept" + "ok").
    my goal: the the file should be automatically saved in THE SAME folder the original file is in (seems that can't be achieved and the standard folder is the only thing where to convert in?).
    Personal background for understanding: i have many folders with several ppts in it. Once i send it out to a customer, i always have to convert it into a pdf. thats why i want to save time (i know that i can convert it directly + send per mail, but i want an up-to-date copy of the pdf in the folder as well).
    B] - "the automated solution"- @Sandeep:
    i just watched your link http://tv.adobe.com/watch/acrobat-tips-and-tricks/automating-tasks-in-acrobat/
    about batch processing and i think its really helpful if i want to convert ALL of the files in one folder.
    1 question regarding this: are the subfolders also affected?
    As i understood from the video, i choose 1 "watched folder" and a "destination folder" (can be the same). E.g i have 1 big folder "designs" with many subfolders. I create a batch converting ppts to pdf to "the same folder" Once i run my batch, it converts ppts in the chosen folder "designs" + all subfolders into the same folder, right?
    If this is the case, i get too many pdfs, for i only need the latest ppt-version to be converted (copies of old ppts are also in the files) ;(.
    Do you have an idea how can i solve this?
    Now we are very near to the end-solution of my goal:
    i need this option "to the same folder" in my general settings when i convert a file via right-click. ATM it only works with the standard-folder documents/*.pdf
    In A], my files are now instantly saved with the same name in 1 specific folder. I would be completely happy, if this folder would be alwys the same as the one with the original file (and not 1 specific folder)
    2nd problem with a]: it does not apply to picture files (bmp, jpegs..)
    So if we could solve this, i would be a completely happy girl
    Guys, you are great, thx again for the whole struggle with my concerns!!

  • Moving a file from a directory with the same name to the parent

    Hello,
    I created a directory with the name a.txt and put a file in there called a.txt.
    (This was an accident, I had originally tried to just save a file a.txt in the a.txt directory's parent directory.)
    So I had parent->a.txt->a.txt.
    Then using finder I dragged the a.txt file into the parent directory.
    The replace file dialog came up, as I would expect, to replace the a.txt directory with the a.txt file.
    I clicked replace.
    Then both the directory a.txt and the file a.txt went missing.
    They're not in the Trash.
    The a.txt file is not in the parent directory.
    I understand that there is an underlying process behind moving/replacing/etc., and I understand what I was trying to do is unusual, but this is just crap design.
    PS: I can replicate the problem.
    PSS: I'm using Lion.
    Ian

    Yes.  I also reproduced this.  Looks like a bug.
    You can file a bug report at: http://www.apple.com/feedback/macosx.html

  • Problem when importing two photo galleries with the same name. Please Help!

    Hi Guys,
    I'm not a pro in dreamweaver so I would appreciate if your answer wouldn't be too technical...
    Anyway I have experienced a problem. Heres the sotory, I have been making a websie in DW and used Adobe Bridge CS5 to create a photo gallery SWF file that I would use for my website. The problem is that I want to use two different photo galleries on two different pages however when I save my second photo gallery in bridge, it saves every file with the exact name as the first photo gallery I created and is working fine... Thus when I try to import the photo gallery files into my website folder structure, I find that it asks me to rename them because the files from the first photo gallery are called the exact same names.. Now obviously when I try to rename them dreamweaver gets confused and goes to the wrong folder and uses the images from my first photo gallery in the second one.
    So I guess my question is how can I organize my folder structure to be able to import multiple galleries without dreamweaver getting confused because bridge names all the files the same. Or how could I save the files through bridge so that they have different names and will work fine when I import into DW...
    Thanks and sorry for the essay,
    Patrick

    #1 You cannot have two files / folders or galleries with the same name.  Redo your image Galleries with different names.
    #2 SWF (flash) is not visible to iPhone, iPad, iTouch, Android or other web devices that don't support Flash Player.  These users will see nothing.  You might wish to explore other photo gallery / slideshow options that rely on jQuery instead of Flash technology.  Some links below.  A Google search will reveal many others.
    jQuery WOW Slider
    http://wowslider.com/
    jQuery Cycle
    http://www.malsup.com/jquery/cycle2/
    jQuery Nivo Slider
    http://dev7studios.com/nivo-slider/
    Nancy O.

  • How do I make Applescript to compress 2 filez with the same name?

    Hello guys and thank you for reading this!
    I don't know a lot about programming, but i believe applescript can save my life. What I need is.
    Detecting 2 files with the same name, but differnt extension. (song 1.jpg, song 1.mp3)
    Compressing those 2 files into a single .zip (In the end I would have song 1.jpg, song 1.mp3 and song 1.zip
    And that's it! I know its pretty simple, and I've seen the "Create Archive" in automator, but I don't really know how to tell him which files to Compress.
    Thanks again!

    Hi,
    Try this script :
    set sourceFolder to choose folder
    tell application "System Events"
          {name, name extension} of (files of sourceFolder whose name extension is not "zip")
          my compress2FilesSameName(the result, sourceFolder as string)
          repeat with i in (get folders of sourceFolder) --check in subfolders
                {name, name extension} of (files of i whose name extension is not "zip")
                my compress2FilesSameName(the result, path of i)
          end repeat
    end tell
    on compress2FilesSameName(tList, tFolder)
          set tnames to item 1 of tList
          set tExtensions to item 2 of tList
          set tc to count tnames
          set j to 1
          repeat while j < tc
                tell (item j of tExtensions) to if it is not missing value or it is not "" then
                      set n1 to (count) + 2
                else
                      set n1 to 1
                end if
                tell (item (j + 1) of tExtensions) to if it is not missing value or it is not "" then
                      set n2 to (count) + 2
                else
                      set n2 to 1
                end if
                set name1 to item j of tnames
                set name2 to item (j + 1) of tnames
                if (text 1 thru -n1 of name1) = (text 1 thru -n2 of name2) then -- same name
                      set tFile1 to quoted form of POSIX path of (tFolder & name1)
                      set tFile2 to quoted form of POSIX path of (tFolder & name2)
                      set zipFile to quoted form of POSIX path of (tFolder & (text 1 thru -n1 of name1) & ".zip")
                      do shell script "/usr/bin/zip -j  " & zipFile & " " & tFile1 & " " & tFile2
                      set j to j + 2
                else
                      set j to j + 1
                end if
          end repeat
    end compress2FilesSameName
    if an archive already exists with the same name (in the parent folder of the files to compress) , the ZIP command overwrite this ".zip" file.
    Example  with "song 1.jpg", "song 1.mp3" and "song 1.zip" :
    If "song 1.zip" doesn't exist, the ZIP command create the "song 1.zip" file.
    If "song 1.zip" exist, the ZIP command overwrite the "song 1.zip" file (it will not create a new archive).

  • The same file with the same name need to call two RFC's with the sequence

    i have to pick up the same file with the same name  and call the two RFC in sequence
    scenario.i have xxx.txt file.file should be proces first calling the first rfc .
    I created two different communication channels
    for the first sender file communication channel i should not use processing mode archive,delete,Test
    and only option is set read only.
    if i set the read only the file ..then i can not use the same file again to call second RFC.
    how we can acheive the above scenario?
    Regards,
    Hyma

    If you want to file need to be picked up twice in same folder, it seems it is hard for PI adapter to achieve it, you should look for API's that control adapters availibility.
    But if you have different folder, then it make your scenario simpler since you can process first time, then output to another folder, configure another adapter to pick up from different folder.
    Regards
    Liang

  • Cloning OS2 HDD to USB stick hangs at a file with the same name ???

    Hi,
    I'm dragging my MacIntosh HD icon to a large USB stick in order to clone it because I'm going to install OS X Tiger onty my iMac G3/400 DV SE. The copying initiates, it starts, and after a few hundreds of MB's a small window pops up with this remark (translated from Dutch) :
    " The file XXXXX cannot be copied because another file with the same name exists already." The window has two buttons : STOP and Continue. No matter which button I click, the process stops and I'm left with a few hundred MB on my USB stick. Deleting the "double" file doesn't help because a few minutes later another one pops up.
    How is this possible? The USB stick is completely empty! Can anybody tell me what's going on and how to stop this, otherwise I'll never be able to clone the HDD.
    Thanks for your kind information,
    Paul

    It was a bug in Classic OS, which was manifest in certain circumstances. My workaround was, at that time, to isolate the rascal (was possible, like in your case), eliminate it, then add it later.
    Such events may occurs with Mac OS X files too, I cannot figure out why. One or two apps in my software archive usually do that.
    another workaround it to archive it (.zip now, .sit in classic Mac OS), check whether applicable.

  • Create a dir if there exists a file with the same name

    Hi..
    I want to create a directory with file.mkdir(). But I recognize a problem when there is allready a File with the same name.
    Is there any solution to handle a dir and a file with the same name?
    eg: Dir "C:\Windows" and File "C:\Windows"
    wami

    This explains it... use "java Test2 asdsfd" for example. While this example doesn't show it,
    if you try to create a dir with another slash on it c:\blah\ , it still can't be done.
    import java.io.*;
    public class Test2
    public static void main (String args[]) throws Exception
         if (args.length < 1){
         System.out.println("Test2 [name]");
         System.out.println("creating bogus file " +args[0]);
         FileOutputStream fo = new FileOutputStream(args[0]);
         fo.write(55);
         fo.write(55);
         fo.write(55);
         fo.close();
         File x = new File(args[0]);
         if (x.mkdir()) System.out.println("made dir " + args[0]);
         else System.out.println("failed to make dir " + args[0]);
         System.out.println("deleting file " + args[0]);
         x.delete();
         if (x.mkdir()) System.out.println("made dir " + args[0]);
         else System.out.println("failed to make dir " + args[0] + " again !");
    }

  • How to open a file with the same name?

    Hi, now I practicing making web pages where I put sample codes in one directory and I copy them to edit.
    The probrem is, I couldn't open one file while I'm opening another file with the same name.
    Is it possible to open  a file with the same name in Dreamweaver?

    That could be a very error prone practice.
    May I suggest you take advantage of DW "Snippets" feature instead.
    Simply save any blocks of code you will reuse regularly as snippets,
    and give each one a descriptive name you like.
    Then you can simply place your cursor in code view where you wish the code,
    and click insert on the selected item from the snippet panel.

  • Is there any option to recover a file we saved with the same name that other by mistake in a MAC PC

    is there any option to recover a file we saved with the same name that other by mistake in a MAC PC

    There's a slim chance. +*Stop using the drive IMMEDIATELY.+*
    Then see: [Data Recovery|http://web.me.com/pondini/AppleTips/Recover.html].

  • How do you create aligned interactive text boxs in a PDF with the same width and height?

    how do you create aligned interactive text boxs in a PDF with the same width and height?
    Without free hand creating the sizing?

    Assuming by "interactive text boxes" you mean form fields; in Acrobat, make a form field, then copy it and paste. (GIve the pasted copy a different name so they don't genetate the same field feedback.) Now you have two fields of the exact same size. Shift-click or marquee-drag to select both, then right-click and choose a command from the Align, Distribute or Center menu.

  • I'm trying to put movies onto my hard  drive but i can't put the files with the same name onto the hard drive , finder won't let me change the name

    I'm trying to put movies onto my hard  drive but i can't put the files with the same name onto the hard drive , finder won't let me change the name. What am i doing wrong?

    Make a new folder and put them in that different folder. Then the names can be the same as others already on your drive.

  • I tried to make another account on my school Macbook Pro, made the Admin, account with the same name as the one I was using, deleted it and then all my desktop data is gone.

    So, the problem is,
    I used these school Macs right? They're school handed and stuff. Then one day I decided I want admin so I do this thing where I "reset" everything on the Macbook using this Video (at the bottom) http://www.wikihow.com/Reset-a-Lost-Admin-Password-on-Mac-OS-X
    Then I do it, it takes me to the new User. That's not what I want so I shut down, then made an account with the same name as my current account (let's call it Y). Then I delete Y on purpose. I deleted it because I didn't want my school to know I had this account. Realise I wanted it again so I made an account, let's call it X then when I have X I deleted Y. Then I realised my AirDrop name said X so then I made a new account, this time let's call it Z, with Z I delete X and then I deleted Z because I don't want my school to know I have Z but then Z is also the same name as my main/current account. Somehow or something I delete my current account leaving me with Z. Now I can see my account and stuff but don't know how to restore it.
    Picture will be provides later.
    PLEASE PLEASE PLEASE HELP ME. I HAVE SCHOOL TOMORROW AND I DON'T WANT MY PARENTS TO FIND OUT.

    It is a bad idea to hack computer passwords when you don't own the computer
    Good luck with the school and the parents.

  • Two groups with the same name in File and LDAP realms

    Hi,
    I configured WLS 6.0 SP1 to use an LDAP caching realm
    as default one. In the LDAP server (Netscape Directory)
    I have a group called Administrators. There is a group
    with the same name in WLS own File Realm. When I click
    on the Groups menu item in the administration console
    I only get the Administrators group from the File Realm
    listed. Is that expected? What will happen if I protect
    a resource ti the Administrators group? Which one will
    prevail - the one from the LDAP or the one from File
    Realm? Or maybe the two will be merged?
    Regards,
    Plamen Petrov
    AstraZeneca
    Sweden

    Hi
    First of all I want to know that where you created your class, In SE24 or in any programm.
    if in SE24, then go to se24 open that class go to methods tab and check if that method name accurs at two places, if not, then
    click on that method and check the code.
    or if in a program.
    then you must have defined like
    class <class name> definition.
    public section
    method <method name>
    endclass.
    class <class name> implementation.
    method <method name>
      code for that method.
    endclass.
    It might be possible you have set the implementation part twice for that particular method, So please check and delete one implementation for that method.
    Thanks
    Lalit Gupta

  • Updating vs. Deleting Folder files with the same name

    Hello all,
    Bear with me as I try to explain this.
    First off, I'm a long time Windows user who just happily converted to Mac. I'm loving my mac so far, but I've run into a snag that I hope to get clarification on.
    Let me set up a scenario on how this works with Windows.
    Let's say I have two folders/root directories labeled as today's date "20100729" with image files in them. Each folder has different picture file names. In other words, the files in each of folders are different. The only thing that is the same is the Folder/Directory name, which in this case is "20100729".
    So, in a windows environment let's say that each of these folders (with the same name) are located on 2 hard drives (A & B). If I take the folder from drive "A" and drop it in drive "B", windows seamlessly combines the files from both folders into one.
    On the flip side, when doing the same thing on my Mac, the entire folder contents from drive B gets replaced from drive A, even though the file names are all different. Which is very annoying.
    If you understand what I'm saying and know of a way for this to work the "Windows" way please let me know.
    Thanks in advance for your help. Let me know if you need further clarification.
    Cheers,
    - Jeff

    Use the ditto command in the Terminal, which is in the /Applications/Utilities/ folder; for instructions on its use, enter 'man ditto' without the quote marks into the Terminal prompt.
    (53065)

Maybe you are looking for