如何使用.jpg
将文件夹中的所有FileInputStream
复制到另一个文件夹?
目前,我将其用于将照片复制到我的SMB共享:
protected String doInBackground(String... params) {
File file = new File("/sdcard/Data/pics/IMG.jpg");
String filename = file.getName();
NtlmPasswordAuthentication auth1 = new NtlmPasswordAuthentication(
servername, username, password);
try {
SmbFile sfile = new SmbFile(servername + "/" + filename, auth1);
if (!sfile.exists())
sfile.createNewFile();
sfile.connect();
InputStream in = new FileInputStream(file);
SmbFileOutputStream sfos = new SmbFileOutputStream(sfile);
byte[] buf = new byte[8192];
int len;
while ((len = in.read(buf)) >= 0) {
sfos.write(buf, 0, len);
}
in.close();
sfos.close();
z = "File copied successfully";
} catch (Exception ex) {
z = z + " " + ex.getMessage().toString();
}
return z;
}
}
之前我曾经使用过lambdas,就像这样:
File file = new File(("/sdcard/Data/pics);
File[] jpgFiles = file.listFiles((dir, name) -> name.endsWith(".jpg"));
for (File entry : jpgFiles) {
System.out.println("File: " + entry.getName());
}
但由于我的程序也应该支持旧版Android,我无法使用它。