隨筆-71  評論-5  文章-0  trackbacks-0
           




          錯誤的原因:

               調用第三方支付,出現問題,起先以為是重啟服務器造成的,后來查看源代碼,運行,才發現,第三方回調時被攔截。


          posted @ 2015-03-26 16:36 藤本薔薇 閱讀(175) | 評論 (0)編輯 收藏
          String ids = "as,ad,sdf,qwe,rwer,wfv";
          for(String id:ids.split(",")){
          System.out.println(id);
          }


          結果:
          as
          ad
          sdf
          qwe
          rwer
          wfv
          posted @ 2015-03-18 09:39 藤本薔薇 閱讀(447) | 評論 (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 藤本薔薇 閱讀(209) | 評論 (0)編輯 收藏


           InetAddress address=InetAddress.getLocalHost();

           System.out.println(address.getHostAddress());
          posted @ 2015-03-12 18:55 藤本薔薇 閱讀(369) | 評論 (0)編輯 收藏
           /**
           * Description: 向FTP服務器上傳文件
           * @Version      1.0
           * @param url FTP服務器hostname
           * @param port  FTP服務器端口
           * @param username FTP登錄賬號
           * @param password  FTP登錄密碼
           * @param path  FTP服務器保存目錄
           * @param filename  上傳到FTP服務器上的文件名
           * @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服務器
            // 如果采用默認端口,可以使用ftp.connect(url)的方式直接連接FTP服務器
            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服務器上 *
           * 
           *    int port,// FTP服務器端口
            String username, // FTP登錄賬號
            String password, // FTP登錄密碼
            String path, // FTP服務器保存目錄
            String filename, // 上傳到FTP服務器上的文件名
            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服務器上傳文件
           * @Version      1.0
           * @param url FTP服務器hostname
           * @param port  FTP服務器端口
           * @param username FTP登錄賬號
           * @param password  FTP登錄密碼
           * @param path  FTP服務器保存目錄
           * @param filename  上傳到FTP服務器上的文件名
           * @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服務器
            // 如果采用默認端口,可以使用ftp.connect(url)的方式直接連接FTP服務器
            ftp.login(username, password);// 登錄
            reply = ftp.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
             ftp.disconnect();
             return success;
            }
          //讀取所有文件,根據文件名模糊刪除遠程照片
           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 藤本薔薇 閱讀(145) | 評論 (0)編輯 收藏

          1. 調用遠程接口,返回的是http文件流,打開相關url,就可以直接下載txt文件,
            要對這相關的文件內容進行操作,不保存,可以調用下面這個方法直接讀取文件流內容,測試了下,是可以的




            public
             String getYCFile(String urlPath) {  
          2.         String readStr = "";  
          3.         try {  
          4.             try {  
          5.                 String strUrl = urlPath.trim();  
          6.                 URL url = new URL(strUrl);  
          7.                 HttpURLConnection urlCon = (HttpURLConnection) url.openConnection();  
          8.                 urlCon.setConnectTimeout(10000);  
          9.                 urlCon.setReadTimeout(30000);  
          10.                 BufferedReader in = new BufferedReader(new InputStreamReader(  
          11.                         urlCon.getInputStream(), "GBK"));  
          12.                 String inputLine = " ";  
          13.                 while ((inputLine = in.readLine()) != null) {  
          14.                     readStr += inputLine.trim();  
          15.                 }  
          16.                 in.close();  
          17.                 return readStr;  
          18.             } catch (IOException e) {  
          19.                 readStr = "";  
          20.             }  
          21.         } catch (Exception e) {  
          22.             readStr = "";  
          23.         }  
          24.         return readStr;  
          25.     } 
          posted @ 2015-03-06 15:40 藤本薔薇 閱讀(1076) | 評論 (0)編輯 收藏
           public static boolean delFilesByPath(String path,String str){
           //參數說明---------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+"的文件已經全部刪除成功!");
           }else{
            System.out.println(path+"中包含"+str+"的文件已經刪除失敗或該文件夾下不存在這類文件!");
           }
          }
          posted @ 2015-03-06 10:09 藤本薔薇 閱讀(175) | 評論 (0)編輯 收藏
          posted @ 2015-02-10 13:50 藤本薔薇 閱讀(138) | 評論 (0)編輯 收藏

           Calendar.getInstance().get(Calendar.YEAR)
          posted @ 2015-01-23 00:21 藤本薔薇 閱讀(148) | 評論 (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 藤本薔薇 閱讀(191) | 評論 (0)編輯 收藏
          僅列出標題
          共8頁: 上一頁 1 2 3 4 5 6 7 8 下一頁 
          主站蜘蛛池模板: 祁门县| 茶陵县| 台东市| 郎溪县| 绥德县| 江都市| 广东省| 庆城县| 容城县| 襄樊市| 滨州市| 临泉县| 多伦县| 新沂市| 乌鲁木齐县| 揭阳市| 宁波市| 新民市| 南木林县| 衡南县| 清河县| 清远市| 浮山县| 长沙县| 沾益县| 分宜县| 肇庆市| 台湾省| 丰镇市| 瑞金市| 钟祥市| 荣昌县| 囊谦县| 馆陶县| 黑龙江省| 昌都县| 体育| 晋城| 汉阴县| 体育| 宜兰市|