Solved

grabbing the name of a file

Posted on 2004-09-24
12
187 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
  • 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Apps blocked by Java 9 88
Java exception bubble up 2 21
hibernate example using maven 12 56
Facing this issue for maven proxy setting 2 19
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

791 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