修改文件上传功能
This commit is contained in:
parent
b6a15cbc56
commit
7265a29a6c
@ -9,6 +9,9 @@ import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class FileUtil {
|
||||
/**
|
||||
@ -17,14 +20,14 @@ public class FileUtil {
|
||||
* @param outPath
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void saveFile(InputStream in, String outPath) throws Exception {
|
||||
// FileChannel in = new FileInputStream("src/demo20/data.txt").getChannel(),
|
||||
// out = new FileOutputStream("src/demo20/data2.txt").getChannel();
|
||||
// in.transferTo(0, in.size(), out);
|
||||
// OutputStream osm = new FileOutputStream(outPath);
|
||||
// IOUtils.copy(in, osm);
|
||||
System.out.println("saveFile"+in+" "+outPath);
|
||||
try (OutputStream osm = new FileOutputStream(outPath)) {
|
||||
public static void saveFile(InputStream in, String outPath,String filePath) throws Exception {
|
||||
// System.out.println("saveFile"+in+" "+outPath+" "+filePath);
|
||||
Path dcPath = Paths.get(filePath); // 创建 Path 对象以表示要创建的文件路径
|
||||
//路径不存在的话创建路径
|
||||
if (!Files.exists(dcPath)){
|
||||
Files.createDirectories(dcPath);
|
||||
}
|
||||
try (OutputStream osm = Files.newOutputStream(Paths.get(outPath))) {
|
||||
IOUtils.copy(in, osm);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user