Java Reference
In-Depth Information
/** The size of blocking to use */
protected
protected static
static final
final
int
int
BLKSIZ
=
16384
;
/** String for encoding UTF-8; copied by inclusion from StringUtil. */
public
public static
static final
final
String ENCODING_UTF_8
=
StringUtil
.
ENCODING_UTF_8
;
/** Nobody should need to create an instance; all methods are static */
private
private
FileIO
() {
// Nothing to do
}
/** Copy a file from one filename to another */
public
public static
static
void
void
copyFile
(
String inName
,
String outName
)
throws
throws
FileNotFoundException
,
IOException
{
BufferedInputStream is
=
null
null
;
BufferedOutputStream os
=
null
null
;
try
try
{
is
=
new
new
BufferedInputStream
(
new
new
FileInputStream
(
inName
));
os
=
new
new
BufferedOutputStream
(
new
new
FileOutputStream
(
outName
));
copyFile
(
is
,
os
,
false
false
);
}
finally
finally
{
iif
(
is
!=
null
null
) {
is
.
close
();
}
iif
(
os
!=
null
null
) {
os
.
close
();
}
}
}
/** Copy a file from an opened InputStream to opened OutputStream */
public
public static
static
void
void
copyFile
(
InputStream is
,
OutputStream os
,
boolean
boolean
close
)
throws
throws
IOException
{
byte
byte
[]
b
=
new
new
byte
byte
[
BLKSIZ
];
// the byte read from the file
int
int
i
;
while
while
((
i
=
is
.
read
(
b
)) != -
1
) {
os
.
write
(
b
,
0
,
i
);
}
is
.
close
();
iif
(
close
)
os
.
close
();
}
/** Copy a file from an opened Reader to opened Writer */
public
public static
static
void
void
copyFile
(
Reader is
,
Writer os
,
boolean
boolean
close
)