Solved

grabbing the name of a file

Posted on 2004-09-24
12
190 Views
Last Modified: 2010-03-31
I need to grab the name of an image file stored in a folder, so that I can parse the name of the file.

C:\images\test.jpg
0
Comment
Question by:vcgDevelopers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
  • +1
12 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 12142877
File.getAbsolutePath()
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12142884
       File f = new File("C:\\images\\test.jpg");
        f.getName();
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12142903
Listing the Files or Subdirectories in a Directory: http://javaalmanac.com/egs/java.io/GetFiles.html
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Accepted Solution

by:
armoghan earned 50 total points
ID: 12142916
sorry this is the one
File f = new File("C:\\images\\test.jpg");
f.getParentFile().getName();

it will return images
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12142961
>> f.getName();
Do you need the name of the file given the full path?
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12142986
f.getName();
will give you name of the file and f.getParentFile().getName(); will give parent directory.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12143021
f.getParent() will also return the name of the parent directory
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12149963
What exactly does the questioner want?

;JOOP!
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12150030
Interesting question sciuriware :))

But he has all the options. He can use anyone of them :))
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12150089
I'm just curious, as he/she did not respond to the overwhelming food of answers.
I feel like the question was not correctly asked.

Chance to answer questioner!

;JOOP!
0
 

Author Comment

by:vcgDevelopers
ID: 12162779
If I had a file (NCWV10024.jpg) I need to parse out 10024 as it is the identification number.  An easy method to grab this was desired.

0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12162901
If it's always the last 5 characters of the "stem name" you might:

String s = "NCWV10024.jpg";
int dot = s.indexOf('.'); // check?

String parsed = s.subString(4, dot);

There you are.
;JOOP!
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question