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

📄 test.java

📁 用JAVA实现串口GSM发信息
💻 JAVA
字号:
package com;

import java.io.*;
import javax.swing.JOptionPane;

public class Test {

	public boolean copy(InputStream fi, String to_name) {// 复制文件
		try {
			InputStream from = fi;// 输入流

			File fo = new File(to_name);// 目标文件
			if (!fo.exists()) {//文件不存在
				FileOutputStream to = new FileOutputStream(fo); // 创建文件输出流
				byte[] buffer = new byte[4096];
				int bytes_read;

				while ((bytes_read = from.read(buffer)) != -1)
					// 读,直到EOF
					to.write(buffer, 0, bytes_read);

				from.close(); // 关闭流
				to.close();
			}
		} catch (NullPointerException ee) {
			System.out.println(ee.toString());
			return false;
		} catch (IOException e) {
			System.out.println(e.toString());
			return false;
		}
		return true;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		String s1 = System.getProperty("java.home") + File.separator;
		// s1=C:\ProgramFiles\Java\jre1.6.0_01\		
		System.out.println("to=: " + s1);

		Test tt = new Test();

		// 复制com口插件到jre目录,java访问com口需要插件支持
		InputStream fi1 = Test.class.getResourceAsStream("/unit/win32com.dll");// 取得源文件引用
		InputStream fi2 = Test.class
				.getResourceAsStream("/unit/javax.comm.properties");// 取得源文件引用

		if (tt.copy(fi1, s1 + "bin" + File.separator + "win32com.dll")) {
			if (tt.copy(fi2, s1 + "lib" + File.separator
					+ "javax.comm.properties")) {
			}
		} else
			JOptionPane.showMessageDialog(null,
					"检测到您的系统可能尚未安装java程序访问串口的插件,请参考配置说明进行配置!");

		Gsm_Main_Frame test = new Gsm_Main_Frame();
		test.setBounds(150, 100, 600, 450);
		test.setVisible(true);	

	}
}

⌨️ 快捷键说明

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