Saving File with new file name

I am subclassing JFileChooser and implementing ActionListener for being able to save and open files.
I am using different file extensions (.ac and .ps), and when saving, I first check that the file name has the right extension.
If it doesn't, I add the right extension.
But for some reason it doesn't show my saved new file, even though in the debugger it goes through all the code of saving.
Here is the main portion of my code before the code of saving (adaptee is my JFileChooser):
File ananyaFile = adaptee.getSelectedFile();
String name = ananyaFile.getName();
int l = name.length();
if (!(l >= 4 && name.charAt(l - 3) == '.' &&
((adaptee.getFileFilter() == adaptee.acExtensionFilter &&
name.charAt(l - 2) == 'a' && name.charAt(l - 1) == 'c') ||
(adaptee.getFileFilter() == adaptee.psExtensionFilter &&
name.charAt(l - 2) == 'p' && name.charAt(l - 1) == 's'))))
if (adaptee.getFileFilter() == adaptee.acExtensionFilter)
name = name + ".ac";
ananyaFile = new File(name);
adaptee.setSelectedFile(ananyaFile);
else if (adaptee.getFileFilter() == adaptee.psExtensionFilter)
name = name + ".ps";
ananyaFile = new File(name);
adaptee.setSelectedFile(ananyaFile);
Why does it not show my saved new file? Do I have to set it somewhere else?
Thanks for your time!

Ok, I put the code which adds the extension
File ananyaFile = this.getSelectedFile();
if (ananyaFile == null)
   return;
String name = ananyaFile.getName();
int l = name.length();
if (!(l >= 4 && name.charAt(l - 3) == '.'  &&
   name.charAt(l - 2) == 'a' && name.charAt(l - 1) == 'c')  
   name = name + ".ac";
   ananyaFile = new File(name);
   this.setSelectedFile(ananyaFile);
}into the approveSelection method of my subclass of JFileChooser.
If someone wants to open a file without writing the extension and the file with the extension (which was added in my code) exists, it does get opened.
Also, if someone wants to save a file without writing the extension and the file with the extension (which was added in my code) exists, it does ask if you want to replace the file (as I have programmed).
But if you say yes, or if you want to save a file without the extension that doesn't yet exists (with the extension), it doesn't save it.
However, saving works fine if someone writes the full file name into the File name box.
Well, I would like to allow the user not to write the extension not only for opening a file, but also for saving a file.
Please help! I am getting pretty desperate! Thanks!

Similar Messages

  • Rename recorded avi file with new file name

    Dear all,
    I'm working on capturing video from a web-cam and storing files which use the time stamps as the file names. As my application must start storing the data as quick as possible, so I need to start the realized processor, create/open the datasink in advance, otherwise there will be a 10 sec time lag. In creating the datasink, I set the medialocator pointed to a temp file:TEMP.avi
    I store the files in the same TEMP.avi for each recording and I want to rename the TEMP.avi using the time stamp as the file name.
    I've tried the setOutputLocator() and tried to set the output as 2003_11_02_183023.avi, but it only work once, the next record still use the previous name.
    I've tried the renameto(), but it doesn't work.
    I've also tried the renameFile(), but it prompt "non static .. can not be referenced to static content".
    Are there any way to solve this problem ? It seems to be a simple file renaming problem, but ..
    Thanks in Advance !
    kan

    byte[] aviData = ...; // data from TEMP.AVI
    File file = new File(timestamp);
    FileOutputStream out = new FileOutputStream(file);
    out.write(aviData);
    out.flush();
    out.close();

  • Saving documents with similar file names

    When saving documents with similar file names, I used to be able to hit save as button and go to the file folder I wish to use. I could then click an existing file in the folder to draw in the name and then just modify it slightly to create the new name.
    In Reader DC I get an error saying this is a read only file an can not be saved.  I can save the file if I use a different file name but then I have to go in and rename the file. i.e. if I have a weakly report that I save, I may have the file name "Installerspayroll.we.04.25.15.pdf."
    I used to be able to click on the existing file name to bring it into the name box and then just change the date. The updated version is not allowing me to do that, creating more work.

    I thought you were referring to an admin account within the Adobe program. I am an admin on the machine I am signed into and using while having these problems
    Thank you for this opportunity to share our expertise,
    Michael Mallary
    Treasurer
    Mallary Carpet & Flooring, Inc.
    410-766-6992
    www.mallarycarpet.com<http://www.mallarycarpet.com>
    Earning your unsolicited referrals
    is our number one priority

  • Upload new pdf file with the same name

    We are trying to upload a pdf file with a specific name (i.e
    file.pdf) that has links to it on many pages of a website. We need
    the pdf file to keep the same name but when we try to upload it,
    Contribute is being 'smart' and changing the name so as to not
    overwrite the file on the server. But we WANT to overwrite the file
    on the server. Any ideas on how we can achieve this in Contribute?
    Thanks so much (in advance) for your help!

    Actually, we have the same problem and I believe the answer
    lies in the abilities that your role has assigned to it. The
    solution that ThinkInk gave works *if you are allowed to delete
    files*. If your role doesn't have that permission, then it will
    just upload another copy of the file and rename it.
    It's rather irritating that there isn't more control over
    this...our server is littered with *thousands and thousands* of
    duplicate files that originate from this situation.
    If your administrator wants you to be able to delete files as
    well, then you could get him/her to give you that permission, and I
    believe this will allow you to overwrite the file by using the
    "Publish file from my computer" option described above.

  • How to copy a files spotlight comments for an entire folder and place them in a different file with that same name

    I have the same question in a different discussion but I already marked it as solved because one of the questions was answered. Here's the linke to the other discussion if your interested https://discussions.apple.com/thread/5970421 
    I have movie covers saved as a jpeg for every movie my family and I own. There is about 700 and they each have a comment of the main actors, release dates, and descriptions. This makes it easy to find what to watch.Is there an applescript, automator, program I can download,  or program code supported in xcode that will do the following set of inscructions?
    Take the name of the picture file and spotlight comment, copy and paste it to a movie file's comments to a file with the same name but obviously has different extention. For an example
    In a Pictures folder
    Name: Dark Knight, The.jpeg       Comment: (2008) Genre: Action...             <- copy comment
    In a Movie Folder
    Name: Dark Knight, The.m4v       Comment:                                               <- paste
    and do this for all 700 files

    Clendenen02 wrote:
    where should I run the code? in the terminal, or an applescript, or should put it in xcode and run it from there or the terminal.
    What MrHoffman said.
    But if it's easier, you can wrap it in Automator and have Automator ask for the Folders: (Test on a sample of your files before running on all 700 files)
    (do you really own 700 movies??)
    The Workflow is:
    Put this in the Run Shell Script Action (and pass input as arguments":
    PicDir=$1
    MovDir=$2
    for f in $PicDir/*
    do
         if [ ! -d "$f" -a "${f##*.}" = "jpeg" ]; then
              comment=$(mdls -raw -name kMDItemFinderComment "$f")
              if [[ $comment != "(null)" ]]; then
                   picname=${f##*/}
                   movname=${picname%.*}.m4v
                   if [[ -e "$MovDir"/$movname ]]; then
    osascript <<-EOF
    tell application "Finder"
    set comment of file (POSIX file "$MovDir/$movname") to  "$comment"
    end tell
    EOF
                   fi
              fi
         fi
    done
    (BTW, I know that this is a bit of sloppy scripting (wraping an osascript in a Bash Script wrapped in Automator, but it does what you need)

  • Compressor crash when attempting import files with 00* in name

    I produce several short video files every day and name them using a sequential five digit numerical naming convention.
    I'm finding that whenever I'm near, at or shortly after crossing a 100 mark Compressor crashes when I try and import single files with the following filenames (these are the most recent examples):
    20993
    21000
    21001
    21005
    The only way to import these problematic files is to select the file before, or after, then Command click on the filename causing the crash. Click Open to import both into the batch, and then click on the file I first clicked on and hit Delete to remove it from the batch, leaving the file with the problematic name.
    For Example. I want to import 21005 into Compressor for processing, but every time I try and import it Compressor crashes. So I re-launch Compressor, click the little Q button and click on 21004, then press Command and click on 21005. Click Open, import window goes away to reveal the Batch window. Click on 21004, press Delete button on keyboard leaving me with the file that was causing the crash.
    FWIW apart from the file duration/size, there's no difference between these files. In fact I can change the names and the files that used to import fine now crash Compressor when attempt to import with any of the filenames above.
    Here's the info behind two of the problem files and also that of the two adjacent files that import fine:
    (all files: Dimension: 720 x 480. Codecs: DV/DVCPRO - NTSC. Channel Count: 2. Kind: Final Cut Pro Movie File. No color labels.
    20999 (Imports Fine):
    File Size: 394,475,469 bytes
    Duration: 01'44
    21000 (Compressor Crasher):
    File Size: 324,052,925 bytes
    Duration: 01'26
    21001 (Compressor Crasher):
    File Size: 339.730.909 bytes
    Duration: 01'30
    21002 (Imports Fine):
    File Size: 348,707,181 bytes
    Duration: 01'32
    Compressor 2 - 2.0.1
    Dual 2 GHz PowerPC G5
    1.5 B DDR SDRAM
    Mac OS X 10.4.8

    Hello,
    Thanks for the replies/info.
    Yes the Panther and Jaguar install disks are retail versions, not specific machine versions. And the Jaguar ones worked for the Powerbook before.
    The Powerbook I have is the Firewire 500mhz one, Pismo I think it's called. The hard drive is a 60GB one. I didn't have to partition it before.
    Reviewing all the above, it would appear that the problem is me not being able to use an internal, built in CD/DVD drive to install from this time? The only other thing it could be I think is the crash I recently had has had some bad effect -- but that's unlikely right? So, I need to get a new DVD drive? Or is there any other way to get the OS onto the Powerbook without getting another internal DVD/CD drive? Is there anyway to install onto the PB from another machine maybe?
    Does that sound right?: not being able to use internal DVD/CD drive is the source of my current problem?
    Thanks.

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

  • 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 !");
    }

  • Is it possible to have two files with the same name on my Zen To

    Hia,
    Is it possible to have two mp3 files with the same name?; I.e if I'm ripping a Bach CD, there are several tracks that have the name preludium, and I hate to do the rename.
    Also, will I be able to sync my Zen so that It will only recieve new files that have been added since I last connected my Zen to my computer?
    regards,
    Fredrik

    I believe same filename is OK because the Zen Player does not really care about filename. As far as I know, the Zen database of the tracks in the player is based on the track information such as Title, Artist, Album and Genre. This means you cannot have two tracks of the same Title, Artist, Album and Genre in the Zen Player.

  • Finder (or other) replace with newer file functionality?!

    i just realized that i think i have been pretty much willy-nilly overwriting same name files with other same name files without the benefit of having a "do you want to overwrite this OLDER file with this NEWER file" prompt or alternatively a "do you /really/ want to overwrite this NEWER file with this OLDER file prompt".
    i realize i have a lot of data and that my doing this has been somewhat hasty but i guess i have been used to this functionality existing in MS OS explorer for so long i did not think twice about it.
    these files are long under the bridge and it is possible that they exist elsewhere on my HD but can anyone that has experience with "dual use" or major experience with Mac OS help me out there? does this functionality not exist? can i get it with some kind of App?
    i cannot reasonably expect to compare files one to one when sorting my HD so any advice here on automating this in a way that does not involve lots of steps or heavy scripting would also be great.
    TIA

    hi. this is even worse than i thought. hopefully a mac technician or expert will chime in here.
    if you are about to overwrite a newer FOLDER mac os will prompt to let you know if it the "overwriting" file is older (presumably it will also prompt if the overwriting folder is newer but who knows since i did not test it) but if you are about to overwrite a newer FILE it will not give you a prompt.
    to test this you can create a folder on your desktop called "test".
    1. drag and drop a random FILE into this folder.
    2. create an untitled folder on your desktop
    3. create an untitled folder in this test folder.
    4. copy the FILE into the test folder
    5. then copy the untitled folder into the test folder.
    in one case you get a prompt telling you that the overwriting folder is older and in the other case with the FILE you don't get a prompt.
    unless i mixed up the order of creating and copying files this seems like a pretty hair-brained scheme to have for an OS.
    maybe i am missing something.
    BTW i am testing on my desktop which can only go to ML OS.

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

  • How to delete the file with space in name

    Hi
    I want to delete the file "test ex.txt" file.
    i run the following command in command prompt.i can delete the file successfully.
    /bin/rm -f /mnt/"test ex.txt"
    I want to run the command from java.So i am using the following code
    String cmd = "/bin/rm -f /mnt/\"test ex.txt\"";
         Runtime rt = Runtime.getRuntime();
    process = rt.exec(cmd);
    The file was not deleted.
    How to delete the file with space in name?
    Help me

    Use the form of exec that takes an array of command + args.
    arr[0] = "/bin/rm"
    arr[1] = "-f"
    arr[2] = "/home/me/some directory with spaces";Or use ProcessBuilder, which is the preferred replacement for Runtime.exec, and which Runtime.exec calls.

  • How can I overwrite a file with the same name in Content DB?

    Hi All,
    In Content DB if I upload a file with the same name as a previous one, the application shows the warning message:
    " ...You cannot upload "XXXXXX.doc" to "Test 1" because an item with the same name already exists ..."
    And the alternatives are "Create Version" or "Cancel" the operation. Is there any way to overwrite a previous file as we can do it in Oracle Files ?
    Regards
    Harvey

    Hi All,
    Can anybody from the Content DB product development answer this question?
    Regards
    Harvey

  • After installing latest update Realplayer recording no longer works, I think Mozila is using a library file with the same name

    After installing the latest update to Firefox onto Vista operating system the record part of real player no longer works, I think Mozila and Real are using a library file with the same name and the Mozila update is overwriting a Realplayer library file.

    I was giong to say, "Help me, Adobe Joe Kenobi", but it looks like you're growing a beard waiting for an answer, too.
    The same thing happened to me today. I trusted the "update" message since it was from Adobe, and apprently did so at my own peril. Now I get the "failed to load Core dll" message with a secondary reference to a memory address.
    Just an observation, but what good are these forums when there are no answers? I see this problem as "Caused by Adobe Update", and would expect them to troublshoot and offer up a remedy. Since you've been waiting over two months with no response, I suppose it's time to trek off wasting more of my precious time to fix their problem. If I find the solution, I'll post it back to you.
    May the Force be with you.
    Mark

  • SPD 2010 - How to know if a file with a given name already exists in a document library

    Hi,
    I've created a workflow using SPD. One of the steps in there is changing the name of the document to a clean name. This workflow fails if a document with this same name already exists in my document library. Is there a way to check in a SPD workflow if
    a document with a given name already exists in my document library ?
    Marc Nemegeer

    Hi,
    According to your post, my understanding is that you wanted to know if a file with a given name already exists in a document library.
    You can use a SharePoint Designer workflow to achive it.
    To test to see if a document exists, you need to use condition:
    If Current List:Name  equals  [%Current Item:Title%].docx
    Here is a similar thread for you to take a look at:
    http://social.technet.microsoft.com/Forums/en-US/cc227020-ce81-4c08-aee0-a66789d8ad05/test-to-see-if-document-exists?forum=sharepointcustomizationprev
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

Maybe you are looking for

  • Udpate for Final Cut Pro 7

    Hi everyone. What updates are available for FCP version 7 users for download? I have Final Cut Studio 3 and my Final Cut Pro vesion is at 7.0.3 Also, where 8 and 9 paid version? Somehow i missed those. Thanks for any help. Jemmen

  • How do I get a previous version 3.6.8

    I currently have Firefox 4. - my backup is from version 3.6.8 and Mozbackup isn't restoring the back up. Where can I get a safe version of 3.6.8 to install? I'll restore and then upgrade again to 4. Thank you.

  • Warp stabiliser rendering not improved by gpu

    I have two PCs, both of which have an Adobe approved GPU installed.  One PC has an Nvidia card, the other PC an AMD card.  Both PCs/GPUs  are recognised by the Mercury Playback Engine hence enabled in Premiere Pro.  Although generally, I can see the

  • CreatePDF is not working

    I am VERY unhappy with your app. All I tried to do is create a multi-page PDF out of images. I have not created a single PDF with it and would like to return your app. PS: Apple does not provide refunds anymore. If I tell them in Itunes there's a pro

  • MS SQL Error Q2

    Here is my query: <CFQUERY NAME="GetProd"datasource="#APPLICATION.DB#" USERNAME="#APPLICATION.UN#" PASSWORD="#APPLICATION.PW#" BLOCKFACTOR="100">           SELECT Products.Cat, Products.Brief, Products.Title, Min(Products.Image) AS Image, Min(Product