Use Java to set Bing's daily wallpaper to Ubuntu wallpaper

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.