過去数日間、USB フラッシュ ドライブから nexus 7 メモリにファイルをコピーしようとしていました。ファイル名を指定せずにファイルを転送する方法はありますか? これまでの私のコードは次のとおりです。
public void copyFile(File usb, File dst) throws IOException
{
//checks to see if the backup directory is created
if(dst.isDirectory())
{
//displays message saying directory is created
mvfldr.show();
//if else statement checks to see if pen drive drive is connected
if(!usb.exists())
{
//displays message if pen drive is not connected
chkffd2.show();
}
else
{
//displays pen drive is connected to the device
chkffd.show();
String[] children = usb.list();
for(int i=0; i<children.length; i++)
{
copyFile(new File(usb, children[i]), new File(dst, children[i]));
}
}
}
//directory is not created, and create the directory.
else
{
//displaying message saying folder has not been created, and will be created.
bldng.show();
dst.mkdir();
if(!usb.exists())
{
//displaying flash drive has not been connected
chkffd2.show();
}
else
{
//displaying flash drive had been connected.
chkffd.show();
String[] children = usb.list();
for(int i=0; i<children.length; i++)
{
copyFile(new File(usb, children[i]), new File(dst, children[i]));
}
}
}
InputStream in = new FileInputStream(usb);
OutputStream out = new FileOutputStream(dst);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0);
{
out.write(buf, 0, len);
}
in.close();
out.close();
}
});
}
}