apache commons io 1.4

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Natural Language Processing
51.Net
52.Parser
53.PDF
54.Portal
55.Profiler
56.Project Management
57.Report
58.RSS RDF
59.Rule Engine
60.Science
61.Scripting
62.Search Engine
63.Security
64.Sevlet Container
65.Source Control
66.Swing Library
67.Template Engine
68.Test Coverage
69.Testing
70.UML
71.Web Crawler
72.Web Framework
73.Web Mail
74.Web Server
75.Web Services
76.Web Services apache cxf 2.2.6
77.Web Services AXIS2
78.Wiki Engine
79.Workflow Engines
80.XML
81.XML UI
Java Source Code / Java Documentation  » Library » apache commons io 1.4 
Collection of I/O utilities.
License:Apache License
URL:http://commons.apache.org/io/
Description:
Package NameComment
org.apache.commons.io

This package defines utility classes for working with streams, readers, writers and files. The most commonly used classes are described here:

IOUtils is the most frequently used class. It provides operations to read, write, copy and close streams.

FileUtils provides operations based around the JDK File class. These include reading, writing, copying, comparing and deleting.

FilenameUtils provides utilities based on filenames. This utility class manipulates filenames without using File objects. It aims to simplify the transition between Windows and Unix. Before using this class however, you should consider whether you should be using File objects.

FileSystemUtils allows access to the filing system in ways the JDK does not support. At present this allows you to get the free space on a drive.

EndianUtils swaps data between Big-Endian and Little-Endian formats.

org.apache.commons.io.comparator

This package provides various {@link java.util.Comparator} implementations for {@link java.io.File}s.

org.apache.commons.io.filefilter

This package defines an interface (IOFileFilter) that combines both {@link java.io.FileFilter} and {@link java.io.FilenameFilter}. Besides that the package offers a series of ready-to-use implementations of the IOFileFilter interface including implementation that allow you to combine other such filters.

These filter can be used to list files or in {@link java.awt.FileDialog}, for example.

There are a number of 'primitive' filters:

DirectoryFilter Only accept directories
PrefixFileFilter Filter based on a prefix
SuffixFileFilter Filter based on a suffix
NameFileFilter Filter based on a filename
WildcardFileFilter Filter based on wildcards
AgeFileFilter Filter based on last modified time of file
SizeFileFilter Filter based on file size

And there are five 'boolean' filters:

TrueFileFilter Accept all files
FalseFileFilter Accept no files
NotFileFilter Applies a logical NOT to an existing filter
AndFileFilter Combines two filters using a logical AND
OrFileFilter Combines two filter using a logical OR

These boolean FilenameFilters can be nested, to allow arbitrary expressions. For example, here is how one could print all non-directory files in the current directory, starting with "A", and ending in ".java" or ".class":

  File dir = new File(".");
  String[] files = dir.list( 
    new AndFileFilter(
      new AndFileFilter(
        new PrefixFileFilter("A"),
        new OrFileFilter(
          new SuffixFileFilter(".class"),
          new SuffixFileFilter(".java")
        )
      ),
      new NotFileFilter(
        new DirectoryFileFilter()
      )
    )
  );
  for ( int i=0; i<files.length; i++ ) {
    System.out.println(files[i]);
  }

This package also contains a utility class: FileFilterUtils. It allows you to use all file filters without having to put them in the import section. Here's how the above example will look using FileFilterUtils:

  File dir = new File(".");
  String[] files = dir.list( 
    FileFilterUtils.andFileFilter(
      FileFilterUtils.andFileFilter(
        FileFilterUtils.prefixFileFilter("A"),
        FileFilterUtils.orFileFilter(
          FileFilterUtils.suffixFileFilter(".class"),
          FileFilterUtils.suffixFileFilter(".java")
        )
      ),
      FileFilterUtils.notFileFilter(
        FileFilterUtils.directoryFileFilter()
      )
    )
  );
  for ( int i=0; i<files.length; i++ ) {
    System.out.println(files[i]);
  }

There are a few other goodies in that class so please have a look at the documentation in detail.

org.apache.commons.io.input

This package provides implementations of input classes, such as InputStream and Reader.

org.apache.commons.io.output

This package provides implementations of output classes, such as OutputStream and Writer.

org.apache.commons.io.testtools
w_w__w_.__j_a__v__a___2___s_.c___o_m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.