LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-13-2006, 02:20 AM   #1
MRMadhav
Member
 
Registered: Nov 2005
Location: Mauritius
Distribution: PCQLinux, SUSE Linux,Fedora Core 5, Fedora Core 6, Knoppix Live, Kubuntu Edgy, PCLinuxOS
Posts: 167

Rep: Reputation: 30
Question Copying Files having a certain Extension using java


Hi i wanted to know how to copy all the files in a Specific directory having a specified extension. This must work in both linux and windows.
I know how to use java.io.File methods but i don't know if i can actually copy a large number of files through it!
 
Old 06-13-2006, 07:30 AM   #2
MRMadhav
Member
 
Registered: Nov 2005
Location: Mauritius
Distribution: PCQLinux, SUSE Linux,Fedora Core 5, Fedora Core 6, Knoppix Live, Kubuntu Edgy, PCLinuxOS
Posts: 167

Original Poster
Rep: Reputation: 30
Post

I Have looked closely at the File class and tried the following piece of code:

Code:
		File x = new File("C:\\cute\\Hotel\\classes");
		if(x.exists())
		{
			for(int i=0;i<x.listFiles().length;i++)
			{
				System.out.println(x.listFiles()[i].getAbsolutePath());
			}
		}
This has returned:

Code:
C:\cute\Hotel\classes\AddItem.txt
C:\cute\Hotel\classes\agent$1.class
C:\cute\Hotel\classes\agent$2.class
C:\cute\Hotel\classes\agent$3.class
C:\cute\Hotel\classes\agent$4.class
C:\cute\Hotel\classes\agent.class
C:\cute\Hotel\classes\ArrivalList$Report.class
C:\cute\Hotel\classes\ArrivalList.class
C:\cute\Hotel\classes\category.class
C:\cute\Hotel\classes\currencytype.class
C:\cute\Hotel\classes\currency_type.class
C:\cute\Hotel\classes\DepartureList$Report.class
C:\cute\Hotel\classes\DepartureList.class
C:\cute\Hotel\classes\drvsel.class
C:\cute\Hotel\classes\FocusController.class
C:\cute\Hotel\classes\Fontings.txt
C:\cute\Hotel\classes\Hotel.class
C:\cute\Hotel\classes\hoteldet$1.class
C:\cute\Hotel\classes\hoteldet$2.class
C:\cute\Hotel\classes\hoteldet.class
C:\cute\Hotel\classes\hotelfile.class
C:\cute\Hotel\classes\hotelRef.class
C:\cute\Hotel\classes\menuload.class
C:\cute\Hotel\classes\MyVerifier.class
C:\cute\Hotel\classes\ratetype.class
C:\cute\Hotel\classes\room$1.class
C:\cute\Hotel\classes\room.class
C:\cute\Hotel\classes\roomtype.class
C:\cute\Hotel\classes\seasonfile.class
C:\cute\Hotel\classes\taxitype.class
C:\cute\Hotel\classes\tourtype.class
C:\cute\Hotel\classes\HotelInvRep.class
C:\cute\Hotel\classes\HotelInvRep$Report.class
C:\cute\Hotel\classes\airports.class
Now i want to filter these results as to extract only the files with extension *.class and copy them to a different computer.
For that there is the method

x.listFiles(FileFilter filter);


but i don't know how to use that one!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
remove all files with same extension? scratchnz Linux - General 1 11-04-2005 03:40 AM
files with extension rar ankscorek Linux - Software 5 07-25-2005 09:41 PM
Extension files BC1 Linux - Software 5 12-20-2004 03:41 AM
What to do about these files with .new extension? Slovak Slackware 1 11-23-2004 04:50 PM
How program to read files with extension .dat y .cfg files COMTRADE in fedora 1? ivonne Linux - Software 0 11-22-2004 11:42 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration