
錯誤的原因:
調(diào)用第三方支付,出現(xiàn)問題,起先以為是重啟服務(wù)器造成的,后來查看源代碼,運行,才發(fā)現(xiàn),第三方回調(diào)時被攔截。
posted @
2015-03-26 16:36 藤本薔薇 閱讀(174) |
評論 (0) |
編輯 收藏
String ids = "as,ad,sdf,qwe,rwer,wfv";
for(String id:ids.split(",")){
System.out.println(id);
}
結(jié)果:
as
ad
sdf
qwe
rwer
wfv
posted @
2015-03-18 09:39 藤本薔薇 閱讀(442) |
評論 (2) |
編輯 收藏
var arr = [{ name: "john", lang: "js" },{ name: "nailwl", lang: "jquery" },{ name: "吳磊", lang: "ext" }];
$.each( arr, function(index, content)
{
alert( "the man's no. is: " + index + ",and " + content.name + " is learning " + content.lang );
});
posted @
2015-03-17 16:18 藤本薔薇 閱讀(208) |
評論 (0) |
編輯 收藏
InetAddress address=InetAddress.getLocalHost();
System.out.println(address.getHostAddress());
posted @
2015-03-12 18:55 藤本薔薇 閱讀(367) |
評論 (0) |
編輯 收藏
/**
* Description: 向FTP服務(wù)器上傳文件
* @Version 1.0
* @param url FTP服務(wù)器hostname
* @param port FTP服務(wù)器端口
* @param username FTP登錄賬號
* @param password FTP登錄密碼
* @param path FTP服務(wù)器保存目錄
* @param filename 上傳到FTP服務(wù)器上的文件名
* @param input 輸入流
* @return 成功返回true,否則返回false *
*/
public static boolean uploadFile(String url,int port,String username,String password,String path,String filename,InputStream input){
boolean success = false;
FTPClient ftp = new FTPClient();
ftp.setControlEncoding("GBK");
try {
int reply;
ftp.connect(url,port);// 連接FTP服務(wù)器
// 如果采用默認(rèn)端口,可以使用ftp.connect(url)的方式直接連接FTP服務(wù)器
ftp.login(username, password);// 登錄
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
return success;
}
ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
ftp.makeDirectory(path);
ftp.changeWorkingDirectory(path);
ftp.storeFile(filename, input);
input.close();
ftp.logout();
success = true;
} catch (IOException e) {
e.printStackTrace();
} finally {
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (IOException ioe) {
}
}
}
return success;
}
/**
* 將本地文件上傳到FTP服務(wù)器上 *
*
* int port,// FTP服務(wù)器端口
String username, // FTP登錄賬號
String password, // FTP登錄密碼
String path, // FTP服務(wù)器保存目錄
String filename, // 上傳到FTP服務(wù)器上的文件名
String orginfilename // 輸入流文件名
*/
public static void upLoadFromProduction(String url,int port,String username,String password,String path,String filename,String orginfilename) {
try {
FileInputStream in = new FileInputStream(new File(orginfilename));
boolean flag = uploadFile(url, port,username, password, path,filename, in);
System.out.println(flag);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
upLoadFromProduction("127.40.1.80",21,"www", "huahua", "/ali/www/Cash/photo", "123.jpg", "C:/Users/Administrator/Desktop/11.jpg");
}
/**
* Description: 向FTP服務(wù)器上傳文件
* @Version 1.0
* @param url FTP服務(wù)器hostname
* @param port FTP服務(wù)器端口
* @param username FTP登錄賬號
* @param password FTP登錄密碼
* @param path FTP服務(wù)器保存目錄
* @param filename 上傳到FTP服務(wù)器上的文件名
* @param input 輸入流
* @return 成功返回true,否則返回false *
*/
public static boolean uploadFile(String url,int port,String username,String password,String path,String filename,String customerNo,InputStream input){
boolean success = false;
FTPClient ftp = new FTPClient();
ftp.setControlEncoding("GBK");
try {
int reply;
ftp.connect(url,port);// 連接FTP服務(wù)器
// 如果采用默認(rèn)端口,可以使用ftp.connect(url)的方式直接連接FTP服務(wù)器
ftp.login(username, password);// 登錄
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
return success;
}
//讀取所有文件,根據(jù)文件名模糊刪除遠(yuǎn)程照片
FTPFile[] ftpFiles = null;
ftpFiles = ftp.listFiles(path);
for (int i = 0; ftpFiles != null && i < ftpFiles.length; i++) {
FTPFile file = ftpFiles[i];
if (file.isFile()) {
if(file.getName().startsWith(customerNo)|| file.getName().endsWith(customerNo)){
ftp.deleteFile(path+"/"+file.getName());
}
}
}
ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
ftp.makeDirectory(path);
ftp.changeWorkingDirectory(path);
ftp.storeFile(filename, input);
input.close();
ftp.logout();
success = true;
} catch (IOException e) {
e.printStackTrace();
} finally {
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (IOException ioe) {
}
}
}
return success;
}
posted @
2015-03-12 18:13 藤本薔薇 閱讀(144) |
評論 (0) |
編輯 收藏
調(diào)用遠(yuǎn)程接口,返回的是http文件流,打開相關(guān)url,就可以直接下載txt文件,
要對這相關(guān)的文件內(nèi)容進行操作,不保存,可以調(diào)用下面這個方法直接讀取文件流內(nèi)容,測試了下,是可以的
public String getYCFile(String urlPath) { - String readStr = "";
- try {
- try {
- String strUrl = urlPath.trim();
- URL url = new URL(strUrl);
- HttpURLConnection urlCon = (HttpURLConnection) url.openConnection();
- urlCon.setConnectTimeout(10000);
- urlCon.setReadTimeout(30000);
- BufferedReader in = new BufferedReader(new InputStreamReader(
- urlCon.getInputStream(), "GBK"));
- String inputLine = " ";
- while ((inputLine = in.readLine()) != null) {
- readStr += inputLine.trim();
- }
- in.close();
- return readStr;
- } catch (IOException e) {
- readStr = "";
- }
- } catch (Exception e) {
- readStr = "";
- }
- return readStr;
- }
posted @
2015-03-06 15:40 藤本薔薇 閱讀(1073) |
評論 (0) |
編輯 收藏
public static boolean delFilesByPath(String path,String str){
//參數(shù)說明---------path:要刪除的文件的文件夾的路徑---------str:要匹配的字符串的頭
boolean b=false;
File file = new File(path);
File[] tempFile = file.listFiles();
for(int i = 0; i < tempFile.length; i++){
if(tempFile[i].getName().startsWith(str)||tempFile[i].getName().endsWith(str)){
tempFile[i].delete();
b=true;
}
}
return b;
}
public static void main(String[] args) {
String path="F:/Installed---success---go/apache/webapps/images";
String str="181";
if(delFilesByPath(path,str)){
System.out.println(path+"中包含"+str+"的文件已經(jīng)全部刪除成功!");
}else{
System.out.println(path+"中包含"+str+"的文件已經(jīng)刪除失敗或該文件夾下不存在這類文件!");
}
}
posted @
2015-03-06 10:09 藤本薔薇 閱讀(173) |
評論 (0) |
編輯 收藏
posted @
2015-02-10 13:50 藤本薔薇 閱讀(137) |
評論 (0) |
編輯 收藏
Calendar.getInstance().get(Calendar.YEAR)
posted @
2015-01-23 00:21 藤本薔薇 閱讀(145) |
評論 (0) |
編輯 收藏
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.add(Calendar.DAY_OF_MONTH, 1);
System.out.println("增加一天后日期 : "+sf.format(c.getTime()));
posted @
2015-01-21 15:26 藤本薔薇 閱讀(190) |
評論 (0) |
編輯 收藏