Original: Use Java to set Bing's daily wallpaper to Ubuntu wallpaper
Source code: Http://www.zuidaima.com/share/1550463714806784.htm
When I woke up in the morning to browse Bing, I suddenly had the idea of setting Bing's Daily wallpaper to Ubuntu desktop wallpaper, and started writing code at noon when I came back from the computer room. First parse the XML, get the wallpaper, then download the wallpaper, and finally call the Ubuntu command to set the wallpaper.
Run successfully on my ubuntu13.04. It is recommended that this Java file be compiled and packaged into a jar, modifying the Run command for/etc/rc.local to add the jar file before exit 0, as I wrote Java-jar/home/kongkongyzt/wallpaper.jar
This will automatically switch on the wallpaper every day.
Code volume is very small, not standardized places a lot, I hope you point out ~ ~
Package com.zuidaima.swing.demo;/*** @author Www.zuidaima.com**/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 xmldocumentbuilderfactory factory = Documentbuilderfactory.newinstan CE (); Documentbuilder builder = Factory.newdocumentbuilder ();D ocument Document = Builder.parse ("http://www.bing.com/ Hpimagearchive.aspx?format=xml&idx=0&n=8 ");d ocument.normalize (); String relativepath =document.getelementsbytagname ("url"). Item (0). Gettextcontent (); String Path = "http://www.bing.com/" +relativepath;//download the jpg fileURL url =The new URL (path);D atainputstream 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 ");}}
Use Java to set Bing's daily wallpaper to Ubuntu wallpaper