Java 如何使用位置文件(路径)创建多部分文件
我有一个位置文件(C:\fakepath\Code.txt)。我想用这个位置创建多部分文件。我的代码:Java 如何使用位置文件(路径)创建多部分文件,java,Java,我有一个位置文件(C:\fakepath\Code.txt)。我想用这个位置创建多部分文件。我的代码: public void fileUpload(String locationFile) { Path path = Paths.get(locationFile); String name = "Code.txt"; String originalFileName = "Code.txt"; String contentType = "text/plain";
public void fileUpload(String locationFile) {
Path path = Paths.get(locationFile);
String name = "Code.txt";
String originalFileName = "Code.txt";
String contentType = "text/plain";
byte[] content = null;
try {
content = Files.readAllBytes(path);
} catch (final IOException e) {
}
MultipartFile file = new MockMultipartFile(name, originalFileName, contentType, content);
try {
// Get the file and save it somewhere
byte[] bytes = file.getBytes();
Path paths = Paths.get(UPLOADED_FOLDER + file.getOriginalFilename());
Files.write(paths, bytes);
} catch (IOException e) {
e.printStackTrace();
}
}
此外,在这段代码中,我需要键入我的文件名,这不符合我的意见。如何创建多部分文件并保存到某处?在Windows中,位置需要双斜杠“C://fakepath//Code.txt”在Windows中,位置需要双斜杠“C://fakepath//Code.txt”听起来是个坏主意,听起来是个坏主意