Solved

grabbing the name of a file

Posted on 2004-09-24
12
184 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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now