Click to See Complete Forum and Search --> : how to open file with certain name
shereen
Jun 18th, 2006, 03:59 AM
how can i open file that have certain name what i mean that i am interest in certain file that have hallo in it name however it is the total name of file or not
how can i make that
ComputerJy
Jun 18th, 2006, 06:45 AM
If I quite understood your question, and I think nobody can (Explain)
if (file.getName().indexOf("hallo") != -1) {
//Your code here
}
shereen
Jun 18th, 2006, 07:13 AM
thank you for your reply
i will try to explain more
what i mean i make could that is search for certain name to open it
but i donot know all the name of file but part of it i want code that could find all file that have that certain part
thank you again
System_Error
Jun 18th, 2006, 07:35 AM
thank you for your reply
i will try to explain more
what i mean i make could that is search for certain name to open it
but i donot know all the name of file but part of it i want code that could find all file that have that certain part
thank you again
That's exactly what CJ showed you. The indexOf method looks for a piece of a string and returns -1 if the search string does not contain it.
This is exactly what your looking for:
if (file.getName().indexOf("hallo") != -1) {
//Your code here
}
Which is what he posted.
shereen
Jun 18th, 2006, 07:52 AM
thank you very much but when i creat file like
flie f=new file("c:/................")
and write
file.getname();
it give me the last name of file in path and that isnot what i want
say that the path is c:/document............./input
and i want to make search on the files that input folder have
acoording to certain part of name
ComputerJy
Jun 18th, 2006, 09:10 AM
public static void main (String args[]) {
File f = new File("C:/") ;
f.list(new FilenameFilter()
{
public boolean accept (File dir, String name) {
return name.indexOf("hallo") != -1 ;
}
}) ;
}
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.