Results 1 to 4 of 4
Thread: checking file extensions
- 12-04-2009, 04:21 PM #1
Member
- Join Date
- Apr 2009
- Posts
- 26
- Rep Power
- 0
checking file extensions
Hi,
The code i have made i believe should check for a certain file extension and then send it out the socket.
if i remove the "if statement" where it checks for the file type it runs fine only with every file type in that directory being sent to the client. Netbeans does not show any errors at all either.Java Code:public void run() { Server sv = new Server(); File folder = new File(sv.getFilePath()); File[] listOfFiles = folder.listFiles(); out.println(listOfFiles.length); for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { //make sure its a file String fileName = listOfFiles[i].getName(); //put file name into string int pos = fileName.lastIndexOf("."); //find the pos of the . in the filename String ext = fileName.substring(pos + 1); // get extention name and place into string ext if (ext.equals("jpg") ) //check the file extension is a jpg file type { out.println(fileName); //send filename to client } } } }
thanks
gisler
- 12-04-2009, 05:08 PM #2
Possible spellings of a "jpg" extension can be:
"jpg", "jpeg", "JPG", and "JPEG"
Try lowercasing the ext and testing for both spellings.
- 12-04-2009, 05:27 PM #3
Member
- Join Date
- Apr 2009
- Posts
- 26
- Rep Power
- 0
how would that matter since i am simply comparing what is in my ext string to the string "jpg". Wouldn't it just simply output nothing if the spelling was wrong?
Also i have stepped through the program. There is 8 jpg files and 1 desktop.ini file. The if statement does compare the extensions successfully. however the client program freezes unless i remove the
from my server thread.Java Code:if (ext.equals("jpg") )
When the program gets to the end of my run() method it then starts a thread called Thread.java[r/o]. If i am looking at my variables as well it gives me an error saying "Variable information not available, source compiled without -g option]"
Not sure if any of that is of any help. Hope that all makes sense
many thanks
gisler
- 12-05-2009, 01:25 PM #4
Member
- Join Date
- Apr 2009
- Posts
- 26
- Rep Power
- 0
Similar Threads
-
Checking if file exists in a directory
By achilles in forum New To JavaReplies: 7Last Post: 08-10-2009, 02:43 AM -
reading an Html file and checking for urls
By sudukrish in forum Advanced JavaReplies: 1Last Post: 04-25-2009, 01:39 AM -
Declaring Custom File Extensions
By Jesdisciple in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 05-07-2008, 10:44 PM -
Checking of file was modified on the server
By Java Tip in forum Java TipReplies: 0Last Post: 03-02-2008, 07:18 PM -
How to compare file extensions?
By Rubin in forum New To JavaReplies: 1Last Post: 08-05-2007, 09:51 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks