Java小程序之Get优美的Windows聚焦图片

众所周知,Windows10锁屏界面下的背景图片— Windows聚焦,相当的优雅美丽。那该如何把图片取出来,自己另存起来呢?
在这里插入图片描述
经过不断的探索,我找到了Windows聚焦图片的路径,如下
C:/Users/yjhqukq/AppData/Local/Packages/Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy/LocalState/Assets
在这里插入图片描述
这里的文件没有扩展名,拷贝了也没有办法直接用,还得自己给文件加个图片扩展名。美好的图片有很多,一个一个的加扩展名,真是有点烦。所以我就花了点时间弄了个Java小程序,顺便把它变成了一个可执行的jar包,方便操作。
在这里插入图片描述
小瞧下,这段小程序的运行效果


在这里插入图片描述
在文本输入框内输入Windows聚焦路径,确定。


在这里插入图片描述
程序运行完成后,自动弹出目标文件夹(D:/focus)。
是不是很方便呢,如果你喜欢它的话,请留言点赞。


package com.natasha.test;
import javax.swing.*;
import java.awt.*;
import java.io.*;

public class Test {
    public static void main(String[] args) {
        try {
            copyAndRenameFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void copyAndRenameFile() throws IOException {
        String sourceLocation;
        File[] subFiles;
        while (true) {
            sourceLocation = JOptionPane.showInputDialog("请输入Windows10聚焦图片的路径");
            if (sourceLocation.trim().equals("")) {
                JOptionPane.showMessageDialog(null, "请输入路径");
                continue;
            } else {
                subFiles = new File(sourceLocation).listFiles();
                if (subFiles.length == 0) {
                    JOptionPane.showMessageDialog(null, "路径下的文件夹是空的");
                    continue;
                }else{
                    break;
                }
            }
        }

        File destinationFile = new File("D:/focus");
        if (!destinationFile.exists()) {
            destinationFile.mkdir();
        }
        BufferedOutputStream bos;
        BufferedInputStream bis;
        int length;
        byte[] data = new byte[1024 * 8];
        for (File subfile : subFiles) {
            if (!subfile.isFile() || subfile.length() / 1000 < 500) {
                continue;
            }
            String originalName = subfile.getName();
            bos = new BufferedOutputStream(new FileOutputStream(new File(destinationFile, "/" + originalName + ".jpg")));
            bis = new BufferedInputStream(new FileInputStream(subfile));
            while ((length = bis.read(data)) != -1) {
                bos.write(data, 0, length);
                bos.flush();
            }
            System.out.println("...processing...");
            bis.close();
            bos.close();
        }
        System.out.println("processing completely");
        Desktop.getDesktop().open(new File("D:/focus"));

    }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值