import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.net.URL;

public class wallpaper {
	public static void main(String[] argc) throws ParserConfigurationException, SAXException, IOException
	{
		//getting the path of the bing jpg picture via analysis xml
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
		DocumentBuilder builder = factory.newDocumentBuilder();
		Document document = builder.parse("http://www.bing.com/HPImageArchive.aspx?format=xml&idx=0&n=8");
		document.normalize(); 
		String relativePath =document.getElementsByTagName("url").item(0).getTextContent();
		String path ="http://www.bing.com/"+relativePath;
		
		//download the jpg file
		URL url = new URL(path);
		DataInputStream dis = new DataInputStream(url.openStream());
		FileOutputStream fos = new FileOutputStream(new File("/tmp/wallpaper.jpg"));
		byte[] buffer = new byte[1024];
		int length;
		while((length=dis.read(buffer))>0)
		{	
			fos.write(buffer,0,length);
		}
		
		dis.close();
		fos.close();
		
		Process process = Runtime.getRuntime().exec("gsettings set org.gnome.desktop.background picture-uri file:///tmp/wallpaper.jpg");
	}
}
最近下载更多
jkw0823  LV1 2019年12月7日
ziv404  LV1 2019年3月4日
qq1195982987  LV1 2019年3月4日
wsTj666  LV1 2019年2月23日
你高冷  LV12 2017年10月23日
duoqingdehanbao  LV1 2017年8月14日
lintoby  LV2 2016年6月6日
jiabinyuan  LV1 2016年4月19日
fertilizer  LV3 2015年12月20日
lewiskit  LV1 2014年12月1日
最近浏览更多
heqian  LV16 2023年1月10日
hollejianren 2021年10月18日
暂无贡献等级
wei112233  LV15 2020年5月20日
jkw0823  LV1 2019年12月7日
c879244324  LV8 2019年9月4日
youwuzuichen  LV10 2019年8月16日
qq460527381  LV3 2019年5月7日
xielxi  LV4 2019年4月8日
ziv404  LV1 2019年3月4日
qq1195982987  LV1 2019年3月4日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友