帮我用Java写一个代码实现图片的增删查改功能
时间: 2023-03-16 21:44:40 浏览: 62
很高兴为您服务!给您提供一个示例代码,供您参考:import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;public class ImageManager {
// 增加图片
public static void addImage(String path, String name) throws IOException {
Path source = Paths.get(path);
Files.copy(source, Paths.get(name));
}
// 删除图片
public static void deleteImage(File file) {
if (file.exists()) {
file.delete();
}
}
// 查询图片
public static void queryImage(String path) {
File file = new File(path);
if(file.exists()) {
System.out.println("图片存在");
} else {
System.out.println("图片不存在");
}
}
// 修改图片
public static void modifyImage(String path, String name) throws IOException {
Path source = Paths.get(path);
Files.move(source, Paths.get(name));
}
}