aspose file tools*
The moose likes Java in General and the fly likes Extracting the contents of the String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Extracting the contents of the String " Watch "Extracting the contents of the String " New topic
Author

Extracting the contents of the String

Satyajeet Kadam
Ranch Hand

Joined: Oct 19, 2006
Posts: 215
i want to extract the "name of the file" from "Path "
for example path is as follows
file opened "D:\eclipse\POST_5227\gui\Trustdata\Quick.t05"
I want to extract "Quick.t05" in next line
Plese help me to acheive this, please write code ?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


Plese help me to acheive this, please write code ?

Its not in the spirit of this site to write code for people on request. JavaRanch's purpose is as a learning resource. If we do yuor work for you how do you ever learn anything?

Sounds like you need to read up on Regular Expressions. Have a look at the JavaDocs for the java.util.regex package.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
i'll write the code if i can send you the bill :-)
Usualy you show us what you've done so far and where the problem is. Then we help you to solve this problem. We do not write code for you. We do not solve homework.

Take a look at java.util.File class. It offers what you want to do for free :-) Or look at String.indexOf() and String.substring(). Or try the regexp stuff.

pascal
Satyajeet Kadam
Ranch Hand

Joined: Oct 19, 2006
Posts: 215
Extracting a path from a complete filename?
I tried myself but i get exception








xception in thread "AWT-EventQueue-0" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(Unknown Source)
at gui.TaxSystem.actionPerformed(TaxSystem.java:1928)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13868
    
  10

It's much easier than you think. If you have a java.io.File object that contains the path, then just call getName() on it to get just the filename (without the path). See the API documentation of class java.io.File.

[ November 06, 2006: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Extracting the contents of the String
 
Similar Threads
file path in XML
POI
string processing
How to change te temporary folder?
Package javax.servlet, javax.servlet.http does not exist