Java工具类 Tool(逐步添加完善)

		System.out.println(Files.probeContentType(Paths.get(new URI("file:/d:/share/vs2008.exe"))));
		System.out.println(Files.probeContentType(Paths.get(new URI("file:/d:/login.html"))));
		System.out.println(Files.probeContentType(Paths.get(new URI("file:/d:/fuck.txt"))));
		System.out.println(Files.probeContentType(Paths.get(new URI("file:/d:/test.xls"))));
		System.out.println(Files.probeContentType(Paths.get(new URI("file:/d:/test.bmp"))));
		/**
application/x-msdownload
text/html
text/plain
application/vnd.ms-excel
image/bmp
		*/
public class Tool {

    public static String html(String content) {
        if (content == null) {
            return "";
        }
        String html = content;
        // html = html.replace( "'", "'");
        html = html.replaceAll("&", "&");
        html = html.replace("\"", """); // "
        html = html.replace("\t", "  ");// 替换跳格
        html = html.replace(" ", " ");// 替换空格
        html = html.replace("<", "<");
        html = html.replaceAll(">", ">");
        return html;
    }

    public static String unhtml(String content) {
        if (content == null) {
            return "";
        }
        String html = content;
        html = html.replaceAll("&", "&");
        html = html.replace(""", "\"");
        html = html.replace("  ", "\t");// 替换跳格
        html = html.replace("- ", " ");// 替换空格
        html = html.replace(" ", " ");// 替换空格
        html = html.replace("<", "<");
        html = html.replaceAll(">", ">");
        return html;
    }
    	public static boolean isValidFileName(String fileName) {
		if (fileName == null || fileName.length() > 255)
			return false;
		else
			return fileName
					.matches("[^\\s\\\\/:\\*\\?\\\"<>\\|](\\x20|[^\\s\\\\/:\\*\\?\\\"<>\\|])*[^\\s\\\\/:\\*\\?\\\"<>\\|\\.]$");
	}
	
}

判断是否符合基本的json格式

// 判断是否符合基本的json格式
	String msg="";
		if (!msg.matches("^\\{.*")) {
			showDialog(msg);
		}
  /** java 打开url
         Thread tURL = new tOpen(sURL);
		tURL.setPriority(Thread.NORM_PRIORITY / 2);
		tURL.setDaemon(true);
		tURL.start();
                */
	public class tOpen extends Thread
	{
		private String sURL;
		public tOpen(String sIn)
		{
			sURL = sIn;
		}
		@Override
		public void run()
		{
			try
			{
				// File
				if (sURL.startsWith("file://"))
					Desktop.getDesktop().open(new File(sURL.replace("file://", "")));
				// Other
				else
					Desktop.getDesktop().browse(new URI(sURL));
			}
			catch (Exception ex)
			{
				Logger.getLogger(fMain.class.getName()).log(Level.SEVERE, null, ex);
			}
		}
	}

系统托盘

  if (SystemTray.isSupported()) {
            try {
                 Image image = Toolkit.getDefaultToolkit().getImage("src/title_search.png");//定义托盘图标的图片            

                TrayIcon trayIcon = new TrayIcon(image,
                        "音乐程序系统托盘", popupMenu1);
                trayIcon.setImageAutoSize(true);
                SystemTray tray = SystemTray.getSystemTray();
                tray.add(trayIcon);
            } catch (Exception ex) {
                Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
            }

        }




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值