簡體   English   中英

如何根據用戶輸入檢查Amazon S3雲存儲中文本文件存儲中的單詞?

[英]how to check for word in text file store in amazon s3 cloud storage against user input?

我如何匹配存儲在亞馬遜S3雲存儲中的文本文件中的單詞,使其與搜索欄中的用戶輸入不匹配,然后下載特定文件?

可以將您在Amazon S3中的文件公開,然后使用HttpURLConnection進行訪問,如下所示:

    import java.io.*;
    import java.net.HttpURLConnection;
    import java.net.URL;

    class Download
     {public static void main (String args[])
       {String u = "http://s3.amazonaws.com/Bucket/path/file.data";
        String d = download(u);
        System.err.println("Download "+u+"=\n"+d);
       }

      public static String download(String u)
       {final int B = 1024*1024; 

        try 
         {final URL url = new URL(u);
          final HttpURLConnection c = (HttpURLConnection)url.openConnection();
          c.connect();
          final int r = c.getResponseCode(); 
          if (r != 200) 
           {System.err.println("Got response code "+r+", expected 200, cannot download "+u);
            return null;
           }
          System.err.println("Content length="+c.getContentLength());

          final InputStream i = new BufferedInputStream(url.openStream(), B);
          final byte data[] = new byte[B];
          String o = "";

          for(int n = i.read(data); n != -1; n = i.read(data))
           {o += new String(data, 0, n);
           }

          i.close();
          return o;
         }
        catch (Exception e) 
         {System.err.println("Cannot download "+u+" due to "+e);
         }
        return null;
       }
     }

如果您無法公開這些文件,則必須走更復雜的路線:使用Amazon IAM創建用戶,分配用戶權限,生成密鑰/秘密組合,然后使用http://www.microsoft.com/developerworks/cn/docs ://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/index.html 如果您需要有關該路線的幫助,請發回此處。

checkout cloudbash.sh-不僅是grep,還包括用於在S3上存儲數據的任何Linux工具。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM