我如何匹配存储在亚马逊S3云存储中的文本文件中的单词,使其与搜索栏中的用户输入不匹配,然后下载特定文件?
Your files in Amazon S3 can be made public and then accessed using HttpURLConnection, as in:
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;
}
}
If you are unable to make these files public you will have to go the more complex route of using Amazon IAM to create a user, assign the user privileges, generate a key/secret combination and then use the Amazon AWS SDK for Java documented at http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/index.html . Please post back here if you need help with that route.
checkout cloudbash.sh-不仅是grep,还包括用于在S3上存储数据的任何Linux工具。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.