@@ -389,10 +389,12 @@ public static String fileRead( File file, String encoding )
389
389
}
390
390
int count ;
391
391
char [] b = new char [512 ];
392
- while ( ( count = reader .read ( b ) ) > 0 ) // blocking read
392
+ while ( ( count = reader .read ( b ) ) >= 0 ) // blocking read
393
393
{
394
394
buf .append ( b , 0 , count );
395
395
}
396
+ reader .close ();
397
+ reader = null ;
396
398
}
397
399
finally
398
400
{
@@ -439,6 +441,8 @@ public static void fileAppend( String fileName, String encoding, String data )
439
441
{
440
442
out .write ( data .getBytes () );
441
443
}
444
+ out .close ();
445
+ out = null ;
442
446
}
443
447
finally
444
448
{
@@ -515,6 +519,8 @@ public static void fileWrite( File file, String encoding, String data )
515
519
writer = new OutputStreamWriter ( out );
516
520
}
517
521
writer .write ( data );
522
+ writer .close ();
523
+ writer = null ;
518
524
}
519
525
finally
520
526
{
@@ -761,18 +767,23 @@ public static boolean contentEquals( final File file1, final File file2 )
761
767
762
768
InputStream input1 = null ;
763
769
InputStream input2 = null ;
770
+ boolean equals = false ;
764
771
try
765
772
{
766
773
input1 = new FileInputStream ( file1 );
767
774
input2 = new FileInputStream ( file2 );
768
- return IOUtil .contentEquals ( input1 , input2 );
769
-
775
+ equals = IOUtil .contentEquals ( input1 , input2 );
776
+ input1 .close ();
777
+ input1 = null ;
778
+ input2 .close ();
779
+ input2 = null ;
770
780
}
771
781
finally
772
782
{
773
783
IOUtil .close ( input1 );
774
784
IOUtil .close ( input2 );
775
785
}
786
+ return equals ;
776
787
}
777
788
778
789
/**
@@ -813,11 +824,11 @@ public static File toFile( final URL url )
813
824
public static URL [] toURLs ( final File [] files )
814
825
throws IOException
815
826
{
816
- final URL [] urls = new URL [files .length ];
827
+ final URL [] urls = new URL [ files .length ];
817
828
818
829
for ( int i = 0 ; i < urls .length ; i ++ )
819
830
{
820
- urls [i ] = files [i ].toURL ();
831
+ urls [i ] = files [i ].toURI (). toURL ();
821
832
}
822
833
823
834
return urls ;
@@ -1112,6 +1123,14 @@ private static void doCopyFile( File source, File destination )
1112
1123
count = size - pos > FILE_COPY_BUFFER_SIZE ? FILE_COPY_BUFFER_SIZE : size - pos ;
1113
1124
pos += output .transferFrom ( input , pos , count );
1114
1125
}
1126
+ output .close ();
1127
+ output = null ;
1128
+ fos .close ();
1129
+ fos = null ;
1130
+ input .close ();
1131
+ input = null ;
1132
+ fis .close ();
1133
+ fis = null ;
1115
1134
}
1116
1135
finally
1117
1136
{
@@ -1197,6 +1216,10 @@ public static void copyStreamToFile( final InputStreamFacade source, final File
1197
1216
input = source .getInputStream ();
1198
1217
output = new FileOutputStream ( destination );
1199
1218
IOUtil .copy ( input , output );
1219
+ output .close ();
1220
+ output = null ;
1221
+ input .close ();
1222
+ input = null ;
1200
1223
}
1201
1224
finally
1202
1225
{
@@ -2332,6 +2355,10 @@ public static void copyFile( File from, File to, String encoding, FilterWrapper[
2332
2355
}
2333
2356
2334
2357
IOUtil .copy ( reader , fileWriter );
2358
+ fileWriter .close ();
2359
+ fileWriter = null ;
2360
+ fileReader .close ();
2361
+ fileReader = null ;
2335
2362
}
2336
2363
finally
2337
2364
{
0 commit comments