<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>13.0.1</version>
<type>jar</type>
</dependency>
code copy
import com.google.common.io.InputSupplier;
import com.google.common.io.Files;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
.......
.......
public void copyFile(File pathfile, String fileName, final InputStream in) throws IOException {
Files.copy(new InputSupplier<InputStream>() {
@Override
public InputStream getInput() throws IOException {
return in;
}
}, new File(pathfile, fileName));
}
การเรียกใช้
File dir = new File("c:\\temp\\");
InputStream stream = new FileInputStream(new File("helloworld.txt"));
copyFile(dir, "helloworld.txt", stream);
แค่นี้ก็เป็นอันเรียบร้อย
ไม่มีความคิดเห็น:
แสดงความคิดเห็น