Method to obtain filename apart from path

I have a string
String myString = C:\foo\bar\myFile.txt;I wish to obtain only the value myFile.txt, that is the name of the File.
I use the File object
File fileObj = new File( myString );
String fileName = fileObj.getName();Running this in one environment yeilds the desired "myFile.txt". But in another environment it yeilds "C:\foo\bar\myFile.txt".
How can this be?
Thanks for any help

I'm going to assume what may be obvious and that is that the method works only within the current operating system. In another words, it's not a "all knowing" method that can parse a filename from a string using the separator characters of each operatiing system "\" and "/". So it's not an effective means to accomplish what I need when the information is going from one OS, to another...
Yes - It's in the API docs which I'm reading now. I don't know why I made this mistake, unless I was confused by the following..."This class presents an abstract, system-independent view of hierarchial pathnames". But immediately following it says that the prefix strings to the filename are system-dependent.
Edited by: nantucket on May 16, 2008 1:32 PM
Edited by: nantucket on May 16, 2008 1:36 PM

Similar Messages

  • How to obtain a URL from a path in a class' method?

    Hey everyone!
    Newbie here needing to convert the following method from a jsp page into a class for one of our applications.
    I have a method in a class which takes a path (as a string). However, I can't seem to figure out how to have java output the corresponding URL in a jsp page.
    For example, in the jsp file, I would provide something like:
    "./../../../../../../temp/gfx/" as the path.
    The "getRealPath()" method converts it nicely to a URL. However, I can't seem to figure out how to use this method within a class file. Is there a way to obtain the URL from a class' method? If so, how?
    --- old code below ---
    ServletContext application = getServletConfig().getServletContext();
    String msg = "";//#Either the IMG tag or message to be returned.
    File dir = new File(application.getRealPath(IMAGE_DIRECTORY));

    Thanks for that hint!
    Also, we're using Websphere... is there an easy way to take a partial url passed as a string and find the full path for it?
    Example:
    /images/today/
    and have it automatically converted to:
    F:/Inetpub/wwwroot/images/today/
    automatically in java?
    Or is this something where both a full system path and URL need to be passed?
    Thanks!

  • Obtaining file name from the file path given

    hi,
    how to obtain  file name from the file path given

    Hi bharath,
    1. PC_SPLIT_COMPLETE_FILENAME
    2.
    DATA : path LIKE pcfile-path.
    DATA : extension(5) TYPE c.
    path = filename.
    CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'
    EXPORTING
    complete_filename = path
    * CHECK_DOS_FORMAT =
    IMPORTING
    * DRIVE =
    extension = extension
    name = name
    * NAME_WITH_EXT =
    * PATH =
    EXCEPTIONS
    invalid_drive = 1
    invalid_extension = 2
    invalid_name = 3
    invalid_path = 4
    OTHERS = 5
    regards,
    amit m.

  • Obtaining the full file path specification from Flash Movie and QuickTime icons?

    How do you obtain the full file path specification from Flash
    Movie and QuickTime icons? I want the path and the file name that
    is contained in these icons. I am using a "dive" to run through the
    icons of a file, and when I come upon these two types of icons, I
    want to obtain the above information that is contained in them. I
    certainly can look in the property dialog box to get this info, but
    there are many icons in these files, and I want to generate a list
    of info based upon the various types of icons that I am processing.
    Thanks

    > How do you obtain the full file path specification from
    Flash Movie and
    > QuickTime icons? I want the path and the file name that
    is contained in
    > these
    > icons. I am using a "dive" to run through the icons of a
    file, and when I
    > come
    > upon these two types of icons, I want to obtain the
    above information that
    > is
    > contained in them. I certainly can look in the property
    dialog box to get
    > this
    > info, but there are many icons in these files, and I
    want to generate a
    > list of
    > info based upon the various types of icons that I am
    processing. Thanks
    >
    For Flash
    Trace(GetIconProperty(iconID, #pathName))
    for QuickTime
    Trace(GetIconProperty(IconID, #filename))
    For full scripting reference for each of these sprites, open
    up the
    Properties panel for each sprite and press the Help button
    that appears on
    the properties page ... or else navigate to these folders for
    the Flash and
    QT help
    C:\Program Files\Macromedia\Authorware
    7.0\xtras\FlashAsset\Help
    C:\Program Files\Macromedia\Authorware
    7.0\xtras\QuicktimeAsset\Help
    You don't want to know how many times I asked Macromedia to
    stop hiding that
    Help!
    Steve
    http://twitter.com/Stevehoward999
    Adobe Community Expert: eLearning, Mobile and Devices
    European eLearning Summit - EeLS
    Adobe-sponsored eLearning conference.
    http://www.elearningsummit.eu

  • Regexp problem when extracting filename from path

    I'm trying to extract filename and full path from string: \dir1\dir2\file.name
    import java.util.regex.*;
    public class Main {  
        private static final String REGEX = "(\\S*\\)*(\\S*)";
        private static final String INPUT = "\\dir1\\dir2\\file.name";
        public Main() {    }   
        public static void main(String[] args) {
           Pattern p = Pattern.compile(REGEX);
           Matcher m = p.matcher(INPUT); // get a matcher object
           int count = 0;      
           if(m.find()) {
               count++;          
               System.out.println("group1: "+m.group(1));
               System.out.println("group2: "+m.group(2));                     
    }I expect group1 to be \dir1\dir2\ and group2 file.name
    when I run program exception is thrown:
    Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed group near index 12
    (\S*\)*(\S*)
    ^
    at java.util.regex.Pattern.error(Pattern.java:1650)
    at java.util.regex.Pattern.accept(Pattern.java:1508)
    at java.util.regex.Pattern.group0(Pattern.java:2460)
    at java.util.regex.Pattern.sequence(Pattern.java:1715)
    at java.util.regex.Pattern.expr(Pattern.java:1687)
    at java.util.regex.Pattern.compile(Pattern.java:1397)
    at java.util.regex.Pattern.<init>(Pattern.java:1124)
    at java.util.regex.Pattern.compile(Pattern.java:817)
    at javaapplication2.Main.main(Main.java:15)

    'jverd' is right but if you are just trying to split the INPUT into a path + filename then why not just look for the last '\'. i.e.
    int lastSlash = INPUT.lastIndexOf('\\');
    String group1 = INPUT.substring(0, lastSlash);
    String group2 = INPUT.substring(lastSlash+1);
    As it stands, your example will not give you group 1 as \dir1\dir2. For that you would need something like
    "((?:\\[^\\])*)(\\.*)"
    to make sure you capure all the path in group 1.

  • Methods for Mass Change to Price Condition Records apart from LSMW.

    Hi all,
    Apart from using LSMW, pls let me know if there is any other best way to do Mass Change to 1000 Price Records.
    Rgds,

    try using tcode scat or a program to perform BDC or try with tcode VK32.
    Regards,
    Raghu.

  • Is there a way to obtain a thumbnail from a video in Lightroom?

    Is there a way to obtain a thumbnail from a video in Lightroom? i.e. a small jpeg file.

    I just remembered that there is an undocumented module LrPhotoPictureView:
    http://forums.adobe.com/message/4140432#4140432
    In a quick test, it shows a thumbnail for .mov files in the catalog:
    Shows a 400 x 400 thumbnail for the selected file.
    local Require = require 'Require'.path ("../common")
    local Debug = require 'Debug'.init ()
    require 'strict'
    local LrApplication = import 'LrApplication'
    local LrDialogs = import 'LrDialogs'
    local LrFunctionContext = import 'LrFunctionContext'
    local LrPhotoPictureView = import 'LrPhotoPictureView'
    local LrView = import 'LrView'
    local showErrors = Debug.showErrors
    local function main (context)
        local f = LrView.osFactory()
        local catalog = LrApplication.activeCatalog ()
        local photo = catalog:getTargetPhoto ()
        if #photo == nil then
            LrDialogs.message ("No photo selected")
            return
            end
        local pictureView = LrPhotoPictureView.makePhotoPictureView ({
              width = 400, height = 400, photo = catalog:getTargetPhoto ()})
        local result = LrDialogs.presentModalDialog {
            title = "Thumbnail test", contents = f:column {
                f:static_text {title = photo:getFormattedMetadata ("fileName")},
                pictureView}}
        end
    LrFunctionContext.postAsyncTaskWithContext ("test",
        showErrors (function (context) main (context) end))

  • How to start TreeCellEditor apart from default behaviors

    Hi,
    I'm trying to find the way to start TreeCellEditor apart from default behaviors which are triple mouse click, click-pause-click and F2 (in Windows).
    The only way I found for starting editor in tree is JTree.startEditingAtPath. However the problem is I designed to separate the action(model) from the tree (view). So In my action class, it knows only TreeModel but not JTree.
    How could I set my action class to tell the JTree to start editor? Is there any approach to do so but do not break my design?
    Thanks in advance.

    I had to do a custom JTree to get my editor to work the way you wanted.
    I needed mine to allow a double mouse click. Then when in edit mode have the text default to a 'select all'.
    All of the 'Rollup' items are custom objects but this should give you an idea of what to do.
    class CustomUI extends BasicTreeUI
        protected boolean startEditing(TreePath path, MouseEvent event) {
            // default to standard behavior
            boolean result = super.startEditing(path, event);
            // start editing this node?
            if (result) {
                // start peeling the object to get a handle to the editor
                RollupTree rollupTree = (RollupTree) event.getSource();
                RollupTreeEditor editor = (RollupTreeEditor) rollupTree.getCellEditor();
                // set Icon if node a trader
                RollupNode node = (RollupNode) rollupTree.getSelectionPath().getLastPathComponent();
                if (node.isTrader()) {
                    editor.setEditorIcon(IconLoader.getIcon("Trader.png"));
                JTextField textField = editor.getEditor();
                // they want to default so that the edit text
                // is in selected mode when they first start to edit the field
                textField.selectAll();
            return result;
        }I also did a custom default editor which looks like:
    class RollupTreeEditor extends DefaultTreeCellEditor
        public RollupTreeEditor(final JTree tree, final RollupTreeCellRenderer renderer) {
            super(tree, renderer);
         * Allow people to toggle the icon when in edit mode
         * @param editor Icon
        public void setEditorIcon(Icon editor) {
            editingIcon = editor;
         * If the <code>realEditor</code> returns true to this
         * message, <code>prepareForEditing</code>
         * is messaged and true is returned.
         * @param event EventObject
         * @return boolean
        public boolean isCellEditable(EventObject event) {
            if (event instanceof MouseEvent) {
                // double click for edit
                if (((MouseEvent) event).getClickCount() == 2) {
                    return true;
            return false;
        public DefaultTextField getEditor() {
            return (DefaultTextField)this.editingComponent;
    }Then in my custom JTree I set these up like...
            // turn on tooltips
            ToolTipManager.sharedInstance().registerComponent(this);
            // used by two setters so create reference
            RollupTreeCellRenderer renderer = new RollupTreeCellRenderer();
            // customizing the icons for the tree
            // setting the folder icons
            // renderer.setOpenIcon(IconLoader.getIcon("Open.gif"));
            // renderer.setClosedIcon(IconLoader.getIcon("Folder.gif"));
            renderer.setLeafIcon(null); // drop the icon
            // add renderer to highlight Inventory nodes with Red or Blue text
            setCellRenderer(renderer);
            // set the editor
            setCellEditor(new RollupTreeEditor(this, renderer));
            // set UI to over ride editing event method
            setUI(new CustomUI());A nice touch is to add a mouse listener so if the user clicks out of the editor it cancels the edit mode. So here is the simple call:
            tree.addMouseListener(new MouseAdapter()
                public void mouseClicked(MouseEvent e) {
                    // get handle to tree
                    RollupTree tree = (RollupTree) e.getSource();
                    // exit editor if in edit mode
                    tree.getCellEditor().stopCellEditing();
                public void mouseReleased(MouseEvent e) {
                    if (e.isPopupTrigger()) {
                        menu.show(e.getComponent(), e.getX(), e.getY());
            });Does this help answer your question?

  • Failed to obtain/create connection from connection pool after redeploy

    I have a web application (.war) that uses a jdbc connection pool. The application works fine, however after I redeploy it using the administration console I get "Failed to obtain/create connection from connection pool [ Datavision_Pool ]. Reason : null" followed by "Error allocating connection : [Error in allocating a connection. Cause: null]" from javax.enterprise.resource.resourceadapter and I am forced to restart the instance. I am running Sun Java System Application Server 9.1 (build b58g-fcs)
    using a connection pool to a Microsoft SQL 2000 database using inet software's JDBC drivers. I need to be able to redeploy applications without having to restart the instance. Any help is appreciated.

    I have turned on some additional diagnostics and found out some answers and a work-around, but I think that there may be a bug in the way JDBC connection pool classes are loaded. The actual error was a null pointer in the JDBC driver class in the perpareStatement method. The only line in this method is "return factory.createPreparedStatement( this , sql );" and the only possible NPE would be if the factory was null, which should be impossible because it is a static variable and it is initialized when the class is loaded. The problem occurs because we deploy the JDBC driver .jar file within our .war file, for use when a client doesn't have or want to use connection pooling. Apparently, the connection pool must have picked up some of these classes and when the .war was redeployed, the reference to the factory was lost for existing connections (not sure how). If I remove the JDBC .jar file from the .war, it works, but that wasn't an ideal solution, the other way to get it to work was to change the sun-web.xml file to have <class-loader delegate="true">. We previously had it set to false in version 8.1 because of interference with a different version of the apache Tiles classes, which has now been addressed in version 9.1.
    I still think there is an issue, because the connection pool should never use the application specific classloaders. Am I wrong to believe this?

  • 'Cannot obtain error message from server' when trying to use ODBC

    Post Author: Grant C
    CA Forum: Data Connectivity and SQL
    Hi, I'm developing some reports using Crystal XI on my local PC, using an Oracle 10i back end on a separate server.  The SQL for the report is in a method in an oracle package.
    When I set the datasource location, selecting 'Oracle Server' then entering the details works fine, and the report runs.  However, when I try to use an ODBC connection I get the following error:
    Database Connection Error: 'Cannot obtain error message from server.'
    The ODBC link is set up as a System DSN, which works fine when I test it.  I think I need to use ODBC as some of the reports (which I inherited) seem to fail when run on the Crystal Server, and it seeme to be the ones set up with ODBC which work.
    Any thoughts?  Thanks.

    Hi Mars-
    It sounds like your NI-DAQ installation may have become corrupted. I would suggest uninstalling and reinstalling the DAQmx 7.4 driver to correct this problem and ensure that you're up to date. This download is available here: NI-DAQ 7.4
    If the problem persists you may want to uninstall and reinstall LabVIEW and then NI-DAQ in that order. The error message will usually give an indication as to which VI the error occurred in. Please let us know which VI is failing if you're unable to avoid the error with these suggestions.
    Have a good day-
    Tom W
    National Instruments

  • What is the recommended way to obtain tracking data from carriers post XSI

    We currently run an old version of SAP Business Connector. We are in the process of migrating all interfaces off BC onto PI. The one remaining interface we have problems is the XSI (Express Delivery Interface) interface we have with ECC06 and UPS via the BC server. The interface works but is not stable and we would like to decommission it if we are able.
    I'm not 100% clear but it appears that XSI is no longer the recommended solution for obtaining tracking data from carriers. What is the recommend method today? We'd be happy to use a PI or ABAP solution but would prefer a standard solution that was supported by SAP and UPS.

    Using Time Machine is the simplest way to back up.
    debasencio wrote:
    They don't fit on a standard data DVD and when I try to back it up to my 500GB external hard drive it says its not formatted to files that size.
    How is the drive formatted?
    If it's DOS/FAT32, you can only size file sizes up to 4GB.
    If you are using it on a Mac only, format it Mac OS X HFS+.

  • How to install Pro*C apart from the database?

    I would like to know how one could Pro*C apart from the database. Thanks.

    Just unzip all Instant Client zip files in the same directory, they all have "instantclient_11_2" as first path element,
    so everything will end up in the right place in this directory.
    If your Instant Client directory has a different name, unzip the package somewhere and move all files and
    directories in it to your instant client directory.
    Yours,
    Laurenz Albe

  • Function or method which returns the full PDC path of webdynpro iview

    Hi All,
    I have created a webdynpro application and created a webdynpro Iview in portal and attached this view to a role.  I am looking for any standard function module or method which returns the full PCD path of the webdynpro iview, when it executed from portal.
    Regards,
    H.K.Hayath Basha.

    Well in ABAP, we don't have portal APIs to access potal catalog info.
    The only available Portal Interface is IF_WD_PORTAL_INTEGRATION
    Abhi

  • Automatic Global Activity: Obtain instance vars from "BusinessProcess"

    Hi,
    I need obtain instance vars from BusinessProcess, but i can't find the method for this operation.
    Can some one give me answers about this problem?
    Thank you...

    You have to use the PAPI api inside the designer.
    You have to do something like this:
    Instance myInstance = BusinessProcess.getInstance(Strign instanceId)
    Object instanceVarValue = myInstance.getVar("myInstanceVarName");
    Hope this helps.
    -Pal

  • Whats the Actual use of the Setup table apart from the Full/Init  loads

    Hi  guru's
      could u explain  whats the Actual use of the Setup table apart from the Full/Init  loads  in Lo Extraction

    Hello Guru,
    The Setup table is used mainly for storing the Historical data whereas the new and changed records will be maintained in the Update table.
    By storing the Historical data in the setup table you don't need to disturb the Application table anymore.
    Please go through the following blogs
    /people/sap.user72/blog/2004/12/16/logistic-cockpit-delta-mechanism--episode-one-v3-update-the-145serializer146
    /people/sap.user72/blog/2004/12/23/logistic-cockpit-delta-mechanism--episode-two-v3-update-when-some-problems-can-occur
    /people/sap.user72/blog/2005/01/19/logistic-cockpit-delta-mechanism--episode-three-the-new-update-methods
    /people/sap.user72/blog/2005/04/19/logistic-cockpit-a-new-deal-overshadowed-by-the-old-fashioned-lis
    /people/sap.user72/blog/2005/02/14/logistic-cockpit--when-you-need-more--first-option-enhance-it
    /people/vikash.agrawal/blog/2006/12/18/one-stop-shop-for-all-your-lo-cockpit-needs
    https://websmp201.sap-ag.de/~form/sapnet?_FRAME=CONTAINER&_OBJECT=011000358700002719062002E
    Hope it helps
    Thanks,
    Chandran

Maybe you are looking for

  • Windows 8.1 Pro update caused application to stop working

    We have 3 Surface tablets running a catalog application for circulation.  The program has been running on the Surfaces since September.  After the 8.1 Pro upgrade this week, the application no longer runs.  It depends on Java jars but we do not think

  • Payment differecne posting on vendor clearing document

    Hello,    Kindly let me know wehre is the payment difference accoutn and positng key configugured, my document is showing wrong postings to the cash discount expnse account instead of booking it to the vendor account itself 1     000001     50       

  • SRM Offline Approval via Blackberries is not working

    SRM Experts, We are using SRM 5.0, PI-7.0. We don't have SAP MI (mobile infrastructure) configured in the landscape. Whenever user approves the Shopping cart from blackberry, it does not work. If user approves from MS-Outlook, it works. I heard that

  • Eliminating zeroes after decimal

    HI all,   I have a requirement to delete the trailing zeroes after decimal.   It is a interest rate and it is denoted in EUR.   i.e the number is 0,739000 % Internal declaration of this number is in DEC.   the data type is AZINSSATZ. i want it to be

  • Scatter Chart with different markers

    Hello, I am using APEX4.0, i want to create a scatter chart with multiple Series, How i can associate differents Marker for Series ?????? For example (Cercle for Serie1, rectangle for Series2 , ....etc). Regards. ouadah.