我有位置文件(C:\ fakepath \ Code.txt)。我想用这个位置创建MultipartFile。我的代码:
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();
}
}
同样在这段代码中,我需要输入我的文件名,这对我的意见不正确。如何创建MultipartFile并保存在某个地方?与位置
答案 0 :(得分:0)
在Windows中,您需要双斜杠“C://fakepath//Code.txt”