資源簡介
我用一個類將url打開的網頁保存成圖片格式的功能包裝好了 只要下載 修改相應的url等就可以實現
主要函數 reload String url String picname String jsname
public static void implcmd String cmd
只要將包導入就行
代碼片段和文件信息
import?java.io.BufferedReader;
import?java.io.BufferedWriter;
import?java.io.File;
import?java.io.FileInputStream;
import?java.io.FileNotFoundException;
import?java.io.FileOutputStream;
import?java.io.IOException;
import?java.io.InputStreamReader;
import?java.io.OutputStreamWriter;
import?java.io.UnsupportedEncodingException;
import?java.util.regex.Pattern;
public?class?FileToolsUtil?{
/**
?*?將content寫入file,默認是utf-8編碼,覆蓋寫
?*?@param?path????路徑
?*?@param?name????名稱,帶后綴
?*?@param?content?內容
?*?@return?1????????正常
?*?????????0???UnsupportedEncodingException
?*????????-1???FileNotFoundException
?*????????-2???IOException
?*/
public?static?int?string2file(String?path?String?name?String?content)?{
return?string2file(path?name?content?“utf-8“);
}
/**
?*?
?*???contentд??file?У?????????д???
?*?@param?path???????????file??·??
?*?@param?name???????????file??????????
?*?@param?content?????file?????
?*?@param?charsetName????file????????
?*?@return?1????????????????
?*?????????0???UnsupportedEncodingException
?*????????-1???FileNotFoundException
?*????????-2???IOException
?*/
public?static?int?string2file(String?path?String?name?String?content?String?charsetName)?{
return?string2file(path?name?content?charsetName?false);
}
/**
?*?
?*???contentд??file??
?*?@param?path???????????file??·??
?*?@param?name???????????file??????????
?*?@param?content?????file?????
?*?@param?charsetName????file????????
?*?@param?append??????д???????????true???????β??false?????
?*?@return?1????????????????
?*?????????0???UnsupportedEncodingException
?*????????-1???FileNotFoundException
?*????????-2???IOException
?*/
public?static?int?string2file(String?path?String?name?String?content?String?charsetName?boolean?append)?{
int?flag?=?1;
String?filename?=?path?+?name;
try?{
BufferedWriter?bw?=?new?BufferedWriter(new?OutputStreamWriter(new?FileOutputStream(filename?append)?charsetName));
bw.write(content);
bw.close();
flag?=?1;
}?catch?(UnsupportedEncodingException?e)?{
e.printStackTrace();
flag?=?0;
}?catch?(FileNotFoundException?e)?{
e.printStackTrace();
flag?=?-1;
}?catch?(IOException?e)?{
e.printStackTrace();
flag?=?-2;
}
return?flag;
}
/**
?*????file?????string?file????????gbk
?*?
?*?@param?file
?*?@return
?*/
public?static?String?file2string(File?file)?{
return?file2string(file?“gbk“);
}
/**
?*????file?????string?file???????
?*?
?*?@param?file
?*?@return
?*/
public?static?String?file2string(File?file?String?charset)?{
//???????string
String?output?=?““;
try?{
BufferedReader?input?=?new?BufferedReader(new?InputStreamReader(
new?FileInputStream(file)?charset));
StringBuffer?buffer?=?new?StringBuffer();
int?oneChar;
while?((oneChar?=?input.read())?!=?-1)?{
buffer.append((char)oneChar);
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????381??2014-07-18?19:07??UrltoImage\.classpath
?????文件????????574??2014-07-20?13:04??UrltoImage\.project
?????文件????????658??2014-07-20?13:04??UrltoImage\.settings\.jsdtscope
?????文件?????????71??2014-07-18?19:20??UrltoImage\.settings\org.eclipse.core.resources.prefs
?????文件????????598??2014-07-18?18:11??UrltoImage\.settings\org.eclipse.jdt.core.prefs
?????文件?????????49??2014-07-20?13:04??UrltoImage\.settings\org.eclipse.wst.jsdt.ui.superType.container
?????文件??????????6??2014-07-20?13:04??UrltoImage\.settings\org.eclipse.wst.jsdt.ui.superType.name
?????文件???????4858??2014-07-18?19:20??UrltoImage\bin\FileToolsUtil.class
?????文件???????2132??2014-07-20?13:21??UrltoImage\bin\ImplementsCmd.class
?????文件????????322??2014-07-20?13:16??UrltoImage\bin\phantomjs\baidu.js
?????文件??????13234??2014-07-20?13:16??UrltoImage\bin\phantomjs\baidu.png
?????文件??????15951??2014-01-27?12:43??UrltoImage\bin\phantomjs\ChangeLog
?????文件???????1451??2012-12-13?00:30??UrltoImage\bin\phantomjs\LICENSE.BSD
?????文件????????300??2014-07-17?16:47??UrltoImage\bin\phantomjs\NetToPicMoban.js
?????文件????7009792??2014-01-28?01:12??UrltoImage\bin\phantomjs\phantomjs.exe
?????文件???????4002??2013-07-11?02:25??UrltoImage\bin\phantomjs\README.md
?????文件????????320??2014-07-20?13:21??UrltoImage\bin\phantomjs\sina.js
?????文件????1738863??2014-07-20?13:21??UrltoImage\bin\phantomjs\sina.png
?????文件???????6198??2014-07-18?19:20??UrltoImage\src\FileToolsUtil.java
?????文件???????1087??2014-07-20?13:21??UrltoImage\src\ImplementsCmd.java
?????文件????????322??2014-07-20?13:16??UrltoImage\src\phantomjs\baidu.js
?????文件??????13234??2014-07-20?13:16??UrltoImage\src\phantomjs\baidu.png
?????文件??????15951??2014-01-27?12:43??UrltoImage\src\phantomjs\ChangeLog
?????文件???????1451??2012-12-13?00:30??UrltoImage\src\phantomjs\LICENSE.BSD
?????文件????????300??2014-07-17?16:47??UrltoImage\src\phantomjs\NetToPicMoban.js
?????文件????7009792??2014-01-28?01:12??UrltoImage\src\phantomjs\phantomjs.exe
?????文件???????4002??2013-07-11?02:25??UrltoImage\src\phantomjs\README.md
?????文件????????320??2014-07-20?13:21??UrltoImage\src\phantomjs\sina.js
?????文件????1738863??2014-07-20?13:21??UrltoImage\src\phantomjs\sina.png
?????文件????????323??2014-07-20?13:14??UrltoImage\src\phantomjsbaidu.js
............此處省略9個文件信息
評論
共有 條評論