Java Reference
In-Depth Information
}
/** Copy a data file from one filename to another, alternative method.
* As the name suggests, use my own buffer instead of letting
* the BufferedReader allocate and use the buffer.
*/
public
public
void
void
copyFileBuffered
(
String inName
,
String outName
)
throws
throws
FileNotFoundException
,
IOException
{
InputStream is
=
null
null
;
OutputStream os
=
null
null
;
try
try
{
is
=
new
new
FileInputStream
(
inName
);
os
=
new
new
FileOutputStream
(
outName
);
int
int
count
=
0
;
// the byte count
byte
byte
[]
b
=
new
new
byte
byte
[
BLKSIZ
];
// the bytes read from the file
while
while
((
count
=
is
.
read
(
b
)) != -
1
) {
os
.
write
(
b
,
0
,
count
);
}
}
finally
finally
{
iif
(
is
!=
null
null
) {
is
.
close
();
}
iif
(
os
!=
null
null
) {
os
.
close
();
}
}
}
/**
* Copy all objects found in and under "fromdir", to their places in "todir".
* @param fromDir
* @param toDir
* @throws IOException
*/
public
public static
static
void
void
copyRecursively
(
File fromDir
,
File toDir
,
boolean
boolean
create
)
throws
throws
IOException
{
Debug
.
printf
(
"fileio"
,
"copyRecursively(%s, %s%n"
,
fromDir
,
toDir
);
iif
(!
fromDir
.
exists
()) {
throw
throw new
new
IOException
(
String
.
format
(
"Source directory %s does not exist"
,
fromDir
));
}
iif
(
create
) {
toDir
.
mkdirs
();
}
else
else iif
(!
toDir
.
exists
()) {
throw
throw new
new
IOException
(