You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2006/01/06 01:36:04 UTC
svn commit: r366357 -
/jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java
Author: scolebourne
Date: Thu Jan 5 16:36:01 2006
New Revision: 366357
URL: http://svn.apache.org/viewcvs?rev=366357&view=rev
Log:
Increase certainty that files are closed in case of error
Modified:
jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java
Modified: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java?rev=366357&r1=366356&r2=366357&view=diff
==============================================================================
--- jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java (original)
+++ jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java Thu Jan 5 16:36:01 2006
@@ -27,8 +27,8 @@
import java.net.URL;
import java.util.Collection;
import java.util.Date;
-import java.util.List;
import java.util.Iterator;
+import java.util.List;
import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.io.filefilter.FalseFileFilter;
@@ -815,6 +815,7 @@
//-----------------------------------------------------------------------
/**
* Reads the contents of a file into a String.
+ * The file is always closed.
* <p>
* There is no readFileToString method without encoding parameter because
* the default encoding can differ between platforms and therefore results
@@ -828,8 +829,9 @@
*/
public static String readFileToString(
File file, String encoding) throws IOException {
- InputStream in = new FileInputStream(file);
+ InputStream in = null;
try {
+ in = new FileInputStream(file);
return IOUtils.toString(in, encoding);
} finally {
IOUtils.closeQuietly(in);
@@ -838,6 +840,7 @@
/**
* Reads the contents of a file into a byte array.
+ * The file is always closed.
*
* @param file the file to read
* @return the file contents or null if read failed
@@ -845,8 +848,9 @@
* @since Commons IO 1.1
*/
public static byte[] readFileToByteArray(File file) throws IOException {
- InputStream in = new FileInputStream(file);
+ InputStream in = null;
try {
+ in = new FileInputStream(file);
return IOUtils.toByteArray(in);
} finally {
IOUtils.closeQuietly(in);
@@ -855,6 +859,7 @@
/**
* Reads the contents of a file line by line to a List of Strings.
+ * The file is always closed.
* <p>
* There is no readLines method without encoding parameter because
* the default encoding can differ between platforms and therefore results
@@ -868,8 +873,9 @@
* @since Commons IO 1.1
*/
public static List readLines(File file, String encoding) throws IOException {
- InputStream in = new FileInputStream(file);
+ InputStream in = null;
try {
+ in = new FileInputStream(file);
return IOUtils.readLines(in, encoding);
} finally {
IOUtils.closeQuietly(in);
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org