advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Partners & Affiliates
advertisement
advertisement
Average Rating: 4/5 | Rate this item | 2 users have rated this item.
 Print Print
 
Utility Class Fills in Java's Missing Functionality
Anybody who regularly switches between Perl and Java can find Java lacking in elementary operations. Try out a utility that bundles all the methods and helper classes that Java is missing into one class. 

advertisement
Java programmer seems to live in two worlds. One is the object-oriented world of classes, interfaces, methods, accessibility, and more advanced notions such as patterns, refactorings, aspects, and concerns. The other world—the "real world"—is absolutely independent from the first. It consists of files, folders, copy, compare, and chmod operations. Anybody who regularly switches between Perl and Java can find Java, an otherwise versatile and beautiful language, strangely awkward by comparison. It can seem to lack Perl's elementary operations—operations that have nothing to do with an object model but are essential for down-to-earth programs that deal with the contents of our hard drives.

The Files utility in the MyJavaTools project, a site where I publish freely available, general-purpose Java tools, bundles all the methods and helper classes that Java is missing into one class. This article explores the methods this utility class offers and describes their functionality with regards to J2SE 5.0.

Under the Hood
The methods that the Files utility class provides are very simple:

  • For a filename string, two methods, dirname() and filename(), return the directory name and the file name—like in Perl.
  • getFullPath() returns the full path for a file or a string that contains a file path.
  • path(String dirname, String filepath) calculates the absolute path for a directory and a filepath. If filepath is absolute, it returns it. Otherwise, it is remains relative in the directory specified by dirname.
  • getcwd() returns the current directory name (the contents of the user.dir system property).
  • deleteFile(File file) and deleteFile(String filename) remove a file or the whole tree if it is actually a directory.
  • find(File directory, Pattern pattern), find(String dirname, Pattern pattern), and find(Strind dirname, String pattern) look within the tree for files whose names satisfy the regexp pattern specified.
  • findLatest(String dirname, String pattern), findLatestDirectory(String directory, String pattern), and findLatestFile(String dirname, String pattern) are similar to find() above, but they return at most one file or directory, the one with the latest timestamp. I have found them unusually useful in discovering changes in real time.

I'd love to have more methods of this kind, but some principal problems in Java prevent any platform-independent implementation.

Page 1 of 4
advertisement
  Next Page: Missing or Broken Functionality
Page 1: IntroductionPage 3: Directory Copy
Page 2: Missing or Broken FunctionalityPage 4: Iterating Through Bytes, Characters, and Lines
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES