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);
}
}