⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 botupdater.java

📁 this is a sample of a java bot. use to educate..
💻 JAVA
字号:
import java.io.OutputStream;
import java.io.InputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;

class BotUpdater extends Thread {

	private IRC irc;
	private String channel;

	private String url;

	public BotUpdater(IRC irc, String channel, String url) {
		this.irc = irc;
		this.channel = channel;
		this.url = url;
	}

	public void run() {
		this.irc.sendMessage(this.channel, this.update(Util.getJARLoc()));
	}

	private String update(String path) {
		try {
			URL _url = new URL(this.url);
			OutputStream out = new BufferedOutputStream(new FileOutputStream(path));
			URLConnection conn = _url.openConnection();
			InputStream in = conn.getInputStream();
			byte[] buffer = new byte[in.available()];
			int read;
			while((read = in.read(buffer)) != -1) {
				out.write(buffer, 0, read);
			}
			out.flush();
			in.close();
			out.close();
			return "Update successful!";
		} catch(IOException ioe) {
			return "Update failed, IOException thrown: " + ioe.toString();
		} catch(Exception e) {
			return "Update failed, Exception thrown: " + e.toString();
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -