How to get a file extension

I wonder how to get the portion of text after the last dot in a string.
For example to get .java from my.project.java or .jpg from my-photo.jpg
String[] parts = "test.test.test".split(".");
if(parts.length == 0) return false;
return true;For some reason it returns false!

String#split takes a regex.String[] parts = "test.test.test".split("\\.");But I think you would be better off trying to use lastIndexOf and substring.
db

Similar Messages

  • [CS3][JS] How to get the file type of current document

    Hi,
    How to get the file type of current opening document (e.g., tif, jpeg, png) using JavaScript with Photoshop CS3.
    I am using file object the open the files one by one in the folder (the files sometimes don't have the extensions).
    If the current document is in tiff format then I need to convert to 8-bit, if its an Jpg image then needs to ignore the file.
    Regards,
    Karthik

    Do you really need to know the file type? What about just checking the bit depth?
    var doc = activeDocument;
    if (doc.bitsPerChannel != BitsPerChannelType.EIGHT) {//Not 8 bit
    doc.bitsPerChannel = BitsPerChannelType.EIGHT;
    //do your save etc
    }else{
        //Ignore

  • How to get the files in presentation server while uploading?

    how to get the files in presentation server while uploading?
    give me the function module name

    Hi,
    PARAMETERS:  P_FILE LIKE RLGRAP-FILENAME DEFAULT C_PRES.  "Prsnt Srvr
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
      CALL FUNCTION 'WS_FILENAME_GET'
        EXPORTING
          DEF_PATH         = P_FILE
          MASK             = ',..'
          MODE             = '0 '
          TITLE            = 'Choose File'
        IMPORTING
          FILENAME         = P_FILE
        EXCEPTIONS
          INV_WINSYS       = 1
          NO_BATCH         = 2
          SELECTION_CANCEL = 3
          SELECTION_ERROR  = 4
          OTHERS           = 5.

  • How to get the file size (in bytes) for all files in a directory?

    How to get the file size (in bytes) for all files in a directory?
    The following code does not work. isFile() does NOT recognize files as files but only as directories. Why?
    Furthermore the size is not retrieved correctly.
    How do I have to code it otherwise? Is there a way of not converting f-to-string-to-File again but iterate over all file objects instead?
    Thank you
    Peter
    java.io.File f = new java.io.File("D:/todo/");
    files = f.list();
    for (int i = 0; i < files.length; i++) {
    System.out.println("fn=" + files);
    if (new File(files[i]).isFile())
         System.out.println("file[" + i + "]=" + files[i] + " size=" + (new File(files[i])).length() ); }

    pstein wrote:
    ...The following code does not work. Work?! It does not even compile! Please consider posting code in the form of an SSCCE in future.
    Here is an SSCCE.
    import java.io.File;
    class ListFiles {
        public static void main(String[] args) {
            java.io.File f = new java.io.File("/media/disk");
            // provides only the file names, not the path/name!
            //String[] files = f.list();
            File[] files = f.listFiles();
            for (int i = 0; i < files.length; i++) {
                System.out.println("fn=" + files);
    if (files[i].isFile()) {
    System.out.println(
    "file[" +
    i +
    "]=" +
    files[i] +
    " size=" +
    (files[i]).length() );
    }Edit 1:
    Also, in future, when posting code, code snippets, HTML/XML or input/output, please use the code tags to retain the indentation and formatting.   To do that, select the code and click the CODE button seen on the Plain Text tab of the message posting form.  It took me longer to clean up that code and turn it into an SSCCE, than it took to +solve the problem.+
    Edited by: AndrewThompson64 on Jul 21, 2009 8:47 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to get full file path while uploading a file in flex Applications

    How to get full file path while uploading a file in flex applications.
    FileReference Object is giving file name and other details but not the actual path.
    Is there any workaround to to get the file path?.
    Thanks

    Why not ask in the Flex forum; it is more likely that someone over there knows.

  • How to get XML file using servlets that XI sent to my J2EE appl?

    Hi All!
    I have a scenario like XI sends xml file to j2ee application. In my J2EE application my servlet receives this xml. Will the xml file be in my HTTPServletRequest object? if so how to get that file from Request object.
    Please help me its urgent, Any code help is highly appreciated.
    My xml file will be like this:
    <ns0:Http_Message_Type_Demo
    xmlns:ns0="http://abcdemo.com">
    <Name>ABC</Name>
    <RollNo>123</RollNo>
    <Address>a-4</Address>
    </ns0:Http_Message_Type_Demo>
    somebody should help me!please
    Thanks

    Hi,
    You can use HTTPServletRequest object to get the XML payload.
    BufferedReader reader = request.getReader(); //gets XML payload
    String line = reader.readLine(); // to read the XML payload line by line
    (request is the HTTPServletRequest object)
    Regards,
    Uma

  • How to get PDF file that has been transformed into docx into my filing system so I can work on it???

    How can I get the PDF file that was transformed into a docx file into my filing system to be able to work on it and translate it as the customer requested?

    THanks for your reply.
    Well what happens is I bought the program. It gives you a button to click,
    you log in and then a box opens up asking you to select the file, I go into
    my filing system (in Windows explorer) select the file, and the program
    converts it into docx, my choice.  I can read it there and when I try to
    copy and paste it into my file where the PDF version is saved, it behaves
    like an "image", and I can't save it.... or it saves likes something you
    save on the internet, so you have to go into internet every time you want
    to see it.    I have also pressed any amount of buttons to see if it will
    give me the option to save it any other way, and have found nothing.  What
    I would need is a file in docx.format that I can edit.  People send me
    things in PDF and sometimes I can just copy it off the PDF file and save it
    in WOrd, then I can translate it for them. But sometimes the PDF file
    doesnt allow me to copy the text.  If it is in image form, I cannot work on
    it.  It means printing it, so I can copy type it into Word... and for that
    I certainly wouldnt need to buy a program.  Its just double the work and
    ends up that the job takes twice as long.!
    Sorry  if I am a bit dumb with informatics.  But I simply could not find
    any way whatever to  copy the PDF file that was transformed into Word, in a
    format that would enable me to edit it.
    Kindest regards,
    Margery
    2013/12/2 Test Screen Name <[email protected]>
        Re: How to get PDF file that has been transformed into docx into my
    filing system so I can work on it???
    created by Test Screen Name<http://forums.adobe.com/people/TestScreenName>in *Adobe
    ExportPDF* - View the full discussion<http://forums.adobe.com/message/5890871#5890871

  • How to get Sequence File Name ?

    Hello everybody !!
    I'm using TestStand 3.1 and i would like to get sequence file name. I've tried to use NameOf() function, but without success.
    Of course, I've searched previous posts about the same question, but nothing works.
    Is there someone able to tell me how to get sequence file name ?
    Thanks a lot.
    MrOrange

    MrOrange,
    first of all, the solution i will present only works for saved sequence files.
    you got all information you need within TestStand itself, just browse for RunState.SequenceFile.Path. here you can find the filename. but the path of the file is also included in the string, so this is a part you have to get rid off.
    you can use statements to extract the filename from the path. just search the string for the last occurence of "\\" (searchinreverse!) and then you can retrieve the right() part of the path. beware that right() needs the number of characters you want to extract, not the startindex!!
    hope this helps,
    Norbert B.
    NI Germany
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • Hi How to get XML file from servlet that XI sent to my J2EE appl?

    Hi All!
    I have a scenario like XI sends xml file to j2ee application. In my J2EE application my servlet receives this xml. Will the xml file be in my HTTPServletRequest object? if so how to get that file from Request object.
    Please help me its urgent, Any code help is highly appreciated.
    My xml file will be like this:
    <ns0:Http_Message_Type_Demo
    xmlns:ns0="http://abcdemo.com">
    <Name>ABC</Name>
    <RollNo>123</RollNo>
    <Address>a-4</Address>
    </ns0:Http_Message_Type_Demo>
    somebody should help me!please
    Thanks

    Hi,
    You can use HTTPServletRequest object to get the XML payload.
    BufferedReader reader = request.getReader(); //gets XML payload
    String line = reader.readLine(); // to read the XML payload line by line
    (request is the HTTPServletRequest object)
    Regards,
    Uma

  • Mac OSX 10.9.2 - Starting Editor error 6 appears - says to reinstall - how to get .dgm file?

    Mac OSX 10.9.2 - Starting Editor error 6 appears - says to reinstall - how to get .dgm file?

    Before re-installing, try trashing the prefs and re-launching. Start by quitting PSE11.
    Launch Finder and click the Go menu whilst holding down the Option (alt) key. Then go to Library >> Preferences and clear everything relating to PSE11 which usually means deleting the following files:
    com.adobe.PhotoshopElements.plist
    Adobe Photoshop Elements 11 Paths
    Adobe Photoshop Elements 11 Settings
    If trashing the prefs makes no difference you can download a replacement for PSE11 at the link below.
    http://helpx.adobe.com/photoshop-elements/kb/photoshop-elements-10-11-downloads.html

  • HT4910 Problem, I reseted my iPhone 4S and now I don't know how to get back files.

    Problem, I reseted my iPhone 4S and now I don't know how to get back files. I bought WhatsApp and some other games with money. Can I get them back? I have iCloud account.

    Not sure what it is you are asking, but you can redownload apps from the purchased section of the app store.

  • Anyone know how to get pdf files to print on Mac

    anyone know how to get pdf files to print on  a Mac. When i bring pdf file up and press print a box comes up saying cannot print. When i press that one another comes up saying no pages selected. Everything up to date, rebooted, checked to make sure plugins are there and up to date.

    Might not be exactly what you want and I haven't had time to fully investigate this but take a look at http://www.hanynet.com/waterroof/

  • How to get Media File in Context

    Hello Everyone,
    I have an application on which i need to store and manage millions of media content (can be audio/visual). As i cannot maintain that much content in the WebContext, so i put the content on the different server.
    Now the problem is when someone need to play the media content than that content need to be with in the WebContext other wise the Media Player does not get the URL/Content.
    Now As i have put the data on different server, how i get the files in the Cureent Applications web context????
    I am out of ideas at the moment. Please suggest something. I am using Struts1.3,JSP,JSTL for the presentation layer and Hibernate for the DB Layer.

    You just need a servlet to access the place where the media content is, and stream it back to the client.
    http://balusc.blogspot.com/2009/02/fileservlet-supporting-resume-and.html has an example (and links) for a File/Image servlet that does something similar.
    You may need to adapt it if you are streaming stuff, but it the theory remains the same.
    cheers,
    evnafets

  • How can you hide file extensions?

    Hello i have a ton of pictures in seperate folders with the extensions .JPEG and i really hate that it shows. I have tried going to the finder and unchecking the show all file extensions, but it does not fix that issue. I also saw this in another topic but i haven't been able to understand it.
    Open the Script Editor in the /Applications/AppleScript/ folder and paste in the following:
    tell application "Finder"
    set extension hidden of every file of entire contents of (selection as alias) to true
    end tell
    Select the folder enclosing the documents in the Finder, and press the Run button in the Script Editor. If they are enclosed by multiple folders or are at different levels in the folder structure, select the first folder which encloses all the documents.
    (22397)
    I don't know if it still works. Im also not sure where i put the folder. I have tried programs but they take away the extension and make the picture not open up then.
    Please if you can help

    yes i found it, but this is how i enter it i dont think its right:
    tell application "Finder"
    set extension hidden of every file of entire contents of (selection as alias) to true
    end tell
    /Users....
    then i get Syntax error "/"

  • How do I delete file extensions on files in sub folders?

    I want to delete all file extensions on the files I have in several sub folders.
    If I highlight the files themselves in a folder and run "Get Selected Finder Items", then "Replace Text in Finder Item Names", then it works. However, how can I have Automator choose ALL files in ALL sub folders of a folder and then do it's magic on all those files at once?
    Thanks.

    Does the Notebook software accept aliases? If so, you could rename aliases instead of the main file, so that the original extensions are preserved.
    For your original question, you can use an action to get the folder contents, and adding a filter action will just give you the file names - for example:
    1) *Get Selected Finder Items*
    2) *Get Folder Contents* (repeat for each subfolder found)
    3) *Filter Finder Items* -- remove items that are folders
    4) *Replace Text in Finder Item Names*

Maybe you are looking for

  • How to convert Date type

    I have a JSP to read the date value and use it to update the corresponding column in the table. In the JSP, the data type returned from request.getParameter("hiredate") is java.util.Date. Unfortunately, the CachedRowSet requires the java.sql.Date typ

  • Unisntall window does not open.

    I have Windows 7 Home Premium 64. Having problem with Uninstall. I click on Control Panel window open then click on Uninstall/Remove but window does not open, need to remove some programs. Please help. Thank you.

  • Help please. Have library- no music on ipod.

    The other day I downloaded a bunch of songs and something popped up and said I didn't have any more space for those songs so one of the settings changed and put all of my songs into one playlist. On the actual ipod there weren't any playlists except

  • How to use LabVIEW code in a Thesis?

    Hello, If I write some code, for example, in MATLAB or C++, that I want to include in my thesis as part of a discussion or in the Appendix, it's a fairly straightforward process: copy/paste However, this isn't really an option for LabVIEW code. Even

  • Good OO Swing Design

    I have been programming with Netbeans for a while now, and would like to know the best method / practices in keeping good OO design to a MDI Swing application. I understand the concepts of OO programming and have been able to code good design using s