/**
* Get the all the filenames with absolute path
* All the files fullpath will be store in vector
* @return the path name
*/
public static void getFilesRecursive(File dir,Vector v)
{
if(dir.isDirectory())
{
String path = dir.getAbsolutePath();
String sub[] = dir.list();
for(int i = 0;i<sub.length;i++)
{
File f = new File(path + File.separator + sub[i]);
getFilesRecursive(f,v);
}
}
else
{ String tmp = dir.getAbsolutePath();
v.add(tmp);
//System.out.println(tmp);
} }将返回的Vector,每个Object cast为String,再用IO读出再写往其它地方即可
* Get the all the filenames with absolute path
* All the files fullpath will be store in vector
* @return the path name
*/
public static void getFilesRecursive(File dir,Vector v)
{
if(dir.isDirectory())
{
String path = dir.getAbsolutePath();
String sub[] = dir.list();
for(int i = 0;i<sub.length;i++)
{
File f = new File(path + File.separator + sub[i]);
getFilesRecursive(f,v);
}
}
else
{ String tmp = dir.getAbsolutePath();
v.add(tmp);
//System.out.println(tmp);
} }将返回的Vector,每个Object cast为String,再用IO读出再写往其它地方即可
try {
String srcFileName = "abc.dat";
File srcFile = new File(srcFileName);
buffer[] = new byte[(int)srcFile.length()];
BufferedInputStream input = new BufferedInputStream(new FileInputStream(srcFileName.getName()));
input.read(buffer,0,buffer.length);
input.close();
String dstFileName = "abc_bak.dat";
File dstFile = new File(dstFileName);
BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(dstFilename.getName()));
output.write(buffer,0,buffer.length);
output.flush();
output.close(); } catch(Exception e){
e.printStackTrace();
}