Java Reference
In-Depth Information
* @param base File representing the source, must be a single file.
* @param startingDir
* @param toDir File representing the location, may be file or directory.
* @throws IOException
*/
public
public static
static
void
void
copyRecursively
(
JarFile base
,
JarEntry startingDir
,
File toDir
)
throws
throws
IOException
{
iif
(!
startingDir
.
isDirectory
()) {
throw
throw new
new
IOException
(
String
.
format
(
"Starting point %s is not a directory"
,
startingDir
));
}
iif
(!
toDir
.
exists
()) {
throw
throw new
new
IOException
(
String
.
format
(
"Destination dir %s must exist"
,
toDir
));
}
Enumeration
<
JarEntry
>
all
=
base
.
entries
();
while
while
(
all
.
hasMoreElements
()) {
JarEntry file
=
all
.
nextElement
();
// XXX ensure that it matches starting dir
iif
(
file
.
isDirectory
()) {
copyRecursively
(
base
,
file
,
new
new
File
(
toDir
,
file
.
getName
()));
}
else
else
{
InputStream is
=
null
null
;
OutputStream os
=
null
null
;
try
try
{
is
=
base
.
getInputStream
(
file
);
os
=
new
new
FileOutputStream
(
new
new
File
(
toDir
,
file
.
getName
()));
copyFile
(
is
,
os
,
false
false
);
}
finally
finally
{
iif
(
os
!=
null
null
)
os
.
close
();
iif
(
is
!=
null
null
)
is
.
close
();
}
}
}
}
// Methods that do reading.
/** Open a file and read the first line from it. */
public
public static
static
String
readLine
(
String inName
)
throws
throws
FileNotFoundException
,
IOException
{
BufferedReader is
=
null
null
;
try
try
{
is
=
new
new
BufferedReader
(
new
new
FileReader
(
inName
));