File class

Hello, I have a curiosity question, why doesn't the File+ class provide a method for retrieving the basename of a file excluding the suffix? For example, for the path
_"C:\some\file\path\filename.ext"_
File*.+getName+() returns the string "*filename.ext*"; however, it would be nice if there was a convenience method such as, File*.+getName2()+, for instance, that returned "*filename*".
I know it is trivial to do this programmatically, but I was surprised that this method was missing from File* class. Is there a particular reason for this becauseI do this all the time in Unix and Windows.
Thanks.

I see your point and it's vaild; however, in Unix I use the command "basename ext" specifying the suffix. I was thinking that they could have done the same thing, for instance, create the following method;
"*+public String getName( String sSuffix )+*"
One would have to specify the suffix you want filtered out of the filename. Then, the following code segment;
File file = new File ( "c:\some\file\path\filename.ext" );
System.out.println( file.getName() );
System.out.println ( file.getName ( "ext" ) );would print the lines;
filename.extfilename>
Problem solved and it would be a nice convenience method :)
Thanks

Similar Messages

  • How to convert the javasource file(*.class) to execute file(*.exe)?

    How to convert the javasource file(*.class) to execute file(*.exe)?
    thank you!

    Although i have seen a few programs (that are platform specific) that will embed a small jvm into an exe with your class file, it is generally excepted that you cannot create an executable file using java. The JAR executable file is probably the closest your going to get
    Pete

  • Convert file.class in file.java

    i lost my file.java how to convert my file.class in file.java? help me please!!!!!!!!!!

    search for java decompiler. just know that it won't be anywhere as near easy to read as the original.
    -S-

  • Problem with file.listFiles() of File class??

    Hi all friends,
    Iam facing with one peculiar problem,Iam using [file.listfiles()] method of File class in my program and this method of file class introduced in Java2.Now when Iam runing on Mac OS classic(8 to 9)[it is my client requirement they can't change Mac OS classic to Mac OS X] it is giving me error file.listfiles() not found in java.io package coz in Mac classic I have used MRJ2.2.6(for runtime) and MRJ SDK2.2 which is based on jdk1.1.8 and this method[listfiles()] added in java2.But now for me I can't change this method in program coz it is a big code and I have to change lot of things in my program.Can any one plz tell me can i find any (java.io) package of java2 seperately in the from of .jar or .zip so that i can keep it in my MRJCLASSES folder and from there I can import it in my program.Eagerly waiting for reply.
    Regards
    Bikash

    Just use File.list(). There are minor semantical differences but they are easy to work around.

  • How to declare ftp in File class. I want to display filename of file in FTP

    How to declare ftp in File class. I want to display filename of file in FTP server.
    I try
    File f2= new File("ftp://abc:abc1111@ABC/file");
                   String n[] = f2.list();
                   System.out.print(n[0]);
                   Vector filename = null ;
                   for (int i2 = 0; i2 < n.length; i2++) {
                        filename.add(n[i2]);
    but it is not work
    Thank you.

    You can use Jakarta's net-package to connect to a FTP server.
    Download it here:
    http://jakarta.apache.org/site/downloads/downloads_commons-net.cgi
    Here's a small demo:
    import org.apache.commons.net.ftp.*;
    public class FTPTest {
        private boolean isConnected;
        private FTPClient client;
        public FTPTest() {
            isConnected = false;
            connect();
        private void connect() {
            String server = "server.org";
            String username = "user";
            String password = "password";
            client = new FTPClient();
            try {
                client.connect(server);
                client.login(username, password);
                String[] files = client.listNames();
                for(int i = 0; i < files.length; i++) {
                    System.out.println(files);
    isConnected = true;
    disconnect();
    catch(Exception e) {
    e.printStackTrace();
    private void disconnect() {
    if(isConnected) {
    try {
    client.disconnect();
    isConnected = false;
    catch(Exception e) {
    e.printStackTrace();
    public static void main(String[] args) {
    new FTPTest();

  • The "File" class does not accept my paths

    Hi ,
    I need yo creat an instance of a directory/file using the File class , but it seems to not recognize my paths:
    using :
    File f = new File("c:/Dir1/dir2/file.ext");
    or:
    File f = new File("c:/Dir1/dir2");
    allthow all do exist , when I use the f.exists() it returns false !!!!
    what is missing ?
    thanks , Adaya .

    Hi
    Found my problem - it wasn't the backslahes (one can use both ways '\\' or'/') it was a realy stupid problem..
    thanks any way ,
    Adaya .

  • Java.io.File class file

    hi may i know how can i get this java.io.File class file, where can i download it from to use it.

    Nothing..... just a visit from the Deprecation Fairy..... she was a little plastered and removed
    java.io.File by mistake .... :)

  • 'Basic' external actionscript file/class usage

    Hey All,
    I'm a bit baffled by something that should, in my humble opinion, be a piece of cake...
    The setup is really easy. A simple application with a single textinput, a button and a text component.
    When the button is clicked a function is called that sets the text from the inputfield to the text component.
    code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
        <mx:Script>
            <![CDATA[
                public function click(inputText:String):void {
                    outPutTxt.text = inputText;
            ]]>
        </mx:Script>
        <mx:TextInput x="10" y="10" id="inputTxt"/>
        <mx:Button x="178" y="10" label="Button" id="Btn" click="{click(inputTxt.text)}"/>
        <mx:Text x="251" y="12" text="Text" id="outPutTxt"/>
    </mx:Application>
    As I said, really easy.
    What I want to do is put the function 'click' into an external actionscript file or class. And still be able to, from within the external file, modify the outPutTxt stuff.
    I'm aware that I could create a public bindable variable inside of the external file and then bind the outPutTxt to that variable, but I would really like to be able to 'simply' force the value...
    Is that possible? If yes: how plix
    If it's not possible, I'd like to know as well! And in that case, how would I then re-use the same instance of a class/file in multiple seperate components? Say I got a 'login' thingie where a user logs in (data stored externally in a seperate actionscript file/class) and I want to re-use that information on other pages... Or is this done automatically?
    Any and all comments/answers are higly appreciated!
    Pieter

    Hey Levancho,
    thanks for your answer!! Much appreciated.
    However, the code you proposed threw an error...
    Errormessage:
    ReferenceError: Error #1069: Property outPutTxt not found on controls.Control and there is no default value.
        at controls::Control/btnClick()[C:\...\FlexTest_03\src\controls\Control.as:13]
        at FlexTest_03/__Btn_click()[C:\...\FlexTest_03\src\FlexTest_03.mxml:11]
    So I tried something else where I bind the text in my OutPutTxt to a variable inside of the external class file.
    Code:
    Class:
    package controls
        public class Control
            [Bindable]
            public var outPutText:String = "";
            public function Control()
            public function btnClick(inputText:String):void {
                this.outPutText =  inputText;
    Mxml:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
        <mx:Script>
            <![CDATA[
                import controls.Control;
                [Bindable]
                private var control:Control = new Control();
            ]]>
        </mx:Script>
        <mx:TextInput x="10" y="10" id="inputTxt"/>
        <mx:Button x="178" y="10" label="Button" id="Btn" click="{control.btnClick(inputTxt.text)}"/>
        <mx:Text x="251" y="12" id="outPutTxt" text="{control.outPutText}"/>
    </mx:Application>
    And this basically did what I wanted to do... so I just need to do some major binding between my application and the classes I'll be using for my business logic.
    Now for something else entirely...
    Is there a way for me to pass the instance of my class between flex components?
    Pieter

  • Problemes with the method listFiles() in File class. I'm using JDeveloper 3.0

    Hi!
    Why can't I compile this snip of code?
    I get:
    Error: (19) method listFiles() not found in class java.io.File.
    Here is the code:
    package stream;
    import java.io.*;
    import java.util.*;
    public class myStream {
    public static void main(String[] args) {
    File myFile = new File("D:/myjava");
    File[] str = myFile.listFiles();
    Thanks in advance
    Henning

    There is no method "listFiles()" in "File" class. (JDK 1.1.8)
    You can try to use " list() " method which
    Returns a list of the files in the directory specified by this File object.
    raghu
    null

  • UrlLoader - replace with File class to access external assets

    Hi.
    Just reading up on the File class more than anything because I want to develop on mobile devices. Can I substitute all my urlLoader classes with the File class for my games on the web.
    var prefsFile:File = File.applicationDirectory;
    prefsFile = prefsFile.resolvePath("preferences.xml");
    I feel like this may be a stupid question but I have to ask.
    Cheers

    yes, but you probably don't want to use the applicationDirectory because of security issues.
    and is there some reason you can't use your urlloaders?

  • How to print the image data stored in object of 'java.io.File' Class in jsp

    I have created a file object for the image file in the system temporary directory.Now I want to display it in my page. please tell,How to print the image data stored in object(in my program it is imgr) of 'java.io.File' Class in jsp

    Create a servlet which gets an InputStream of the file and writes it to the OutputStream of the response and call this servlet in `src` attribute. That's basically all.
    Here's an example which covers the most of the minimum needs: [http://balusc.blogspot.com/2007/04/imageservlet.html].

  • How to move(migrate) OAF files(class files,PG files) using tool(Kintana)

    Hi,
    How to move(migrate) OAF files(class files,PG files) using tools(Kintana).
    Just want to know process for moving(migrating) OAF Files(class,PG) one instance to over instance(i.e dev to testing) using tools like kintana. We are planning to PVCS as versioning tool.
    Thanks

    New Line Types need to be added to Kintana Workflows and these line types should be able to use the xmlimport/xmlexport scripts.
    We have customized Kintana to migrate forms personalizations using FNDLOAD.
    I think, Change Management team should be able to address this.
    Srini

  • EJB Class loader and regular Java files class loader.

    Hi,
    Is the EJB's class loader the same as a "regular" java files class loader OR weblogic
    has 2 class loaders, one for each???
    Thanks,
    les.

    les <[email protected]> wrote:
    Hi,
    Is the EJB's class loader the same as a "regular" java files class loader OR weblogic
    has 2 class loaders, one for each???Yes. Exact classloading architecture depends on which WebLogic version you use. If you
    use 6.x+, you may want to read this article:
    http://www.onjava.com/pub/a/onjava/2001/07/25/ejb.html
    Thanks,
    les.--
    Dimitri

  • RenameTo() method in File.class

    I want to know in which platforms the renameTo() method in the File class actually move the file to the detination directory. I have checked with Windows. It does move the file to the targetted directory. What about other platforms??

    YoungWinston wrote:
    supratim wrote:
    My concern is if I am sure that that the renameTo() succeeds in doing its thing[By doing a simple renameTo() on a file and check if it is getting moved],
    can it supply me any perfomrmance boost compared to normal stream based copying and then deleting the file.I think you'll have to describe what you're trying to do, and what you think your alternatives are, a bit better.
    You never know, somebody may have a '3rd way' which is superior to either.
    WinstonMost certainly there may be a lot more ways. All I want to know does the renameTo() method works more faster than the normal stram based copying[which includes creating InputStream  and OutputStream] which looks ugly[catching FileNotFoundException,IOException etc]. Well don't take the "ugly" word otherwise, this just waht I think.
    I have learned that if FileChannel s are used it, it can boost up the copying speed compared to the stream based copying. But channels are normally used where a bigger size of file needs to be transferred. Should I use channels for faster io.
    I am so concerned about the speed because it is preciously what I need to do in my current work. I have to do a lot of io[file moving,copying etc] and my files are also not very big[max 3MB,min 3KB], and I want to know the best way to achieve this in a perfect and of course faster way.

  • File class question

    Hi all,
    I've been playing with the File class (as a way of learning about it) and am confused about the behaviour of the following code.
    This class is uses recursion as a way of getting a file structure.
    import java.io.File;
    public class FileTest {
        public static void main(String[] args) {
            if (args.length == 0) {
                return;
            File file = new File(args[0]);
            processFileList(file);
        public static void processFileList(File f) {
            if (f.isDirectory()) {
                System.out.println("found directory: " + f.getName());
                String fileList[] = f.list();
                for (int i=0; i < fileList.length; i++) {
                    File newF = new File(fileList);
    if (newF.isFile()) {
    System.out.println("Found file in list: " + newF.getName());
    } else {
    System.out.println("Found new directroy is list: " + newF.getName());
    processFileList(newF);
    } else {
    System.out.println("Found file: " + f.getName());
    The command line I use is java FileTest testdir
    The output from the code is:
    found directory: testdir
    Found file in list: FileTest.class
    Found file in list: Hello.class
    Found file in list: LogTest.class
    Found new directroy is list: testdir2
    Found file: testdir2
    The file structure being used is testdir, which contains the three class files and a directory called testdir2. testdir2 contains some java files.
    I don't understand why testdir2 is recognised as not being a file, but is not recognised as being a directory. I changed the code to use isDirectory() rather than isFile(), but the results were similar, testdir2 is not recognised as a directory.
    Any ideas? Thanks,
    dan

    When you instantiate the class java.io.File from a String you should use a pathname or depict the parent directory as well as the abstract file name. Or you could use the method listFiles() of the File class.
    File[] fileList = f.listFiles();

Maybe you are looking for

  • Unable to edit in SharePoint Designer 2010

    I am having problems editing a simple SharePoint Team Site in SharePoint Designer 2010. I'm using SharePoint 2010 Foundation Server. I'm running Windows 8.1. Receive pop up message: Unable to open Web site.  Possible causes: The Web server may not ha

  • I have lost the tools, file, menu at the top tried reloading still wont come back how do i get it back

    while customizing my settings i lost the menu at the top file, edit view , favorites, tools, etc. even if i delete mozilla and reload it i cant get it back

  • How to Park a doc in FB01 !

    Hi All, I have 2 options, 1 is Post a doc 2nd is PArk a doc, I am using FM => PRELIMINARY_POSTING_FB01 for Posting, but for park a doc is this FM help to me ? or anybody help me to park a doc ? IS it available  any BAPI FM or let me know any further

  • Fraudulent e-mails asking for account details

    Sent from my iPad On 8 Jul 2014, at 13:49, Apple <[email protected]> wrote:  Dear iTunes Customer, This is an automatic message by the system to let you know that you have to confirm your account information within 48 hours. Your itunes account has b

  • Add spry menu to external css or template

    I have a working navigation menu at www.reachyourpotential.ca but I haven't used an external style sheet on this website and that seems to be the thing to do these days. I used cs3 to add a spry horizontal menu to a template (standard cs3 2 column).