读取scala中s3中的属性文件
我想读取AWS s3中的.properties文件,并使用scala应用程序中的属性读取scala中s3中的属性文件,scala,amazon-s3,Scala,Amazon S3,我想读取AWS s3中的.properties文件,并使用scala应用程序中的属性 请告诉我是否有任何API用于此或其他方法来解决此问题。您可以执行以下操作: import com.amazonaws.auth.DefaultAWSCredentialsProviderChain import com.amazonaws.services.s3.model.S3Object import com.amazonaws.services.s3.{AmazonS3Client, AmazonS3UR
请告诉我是否有任何API用于此或其他方法来解决此问题。您可以执行以下操作:
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain
import com.amazonaws.services.s3.model.S3Object
import com.amazonaws.services.s3.{AmazonS3Client, AmazonS3URI}
import scala.io.{BufferedSource, Source}
val credentialsProvider = new DefaultAWSCredentialsProviderChain()
val s3Client = new AmazonS3Client(credentialsProvider)
val uri: AmazonS3URI = new AmazonS3URI(filePath)
val s3Object: S3Object = s3Client.getObject(uri.getBucket, uri.getKey)
val source: BufferedSource = Source.fromInputStream(s3Object.getObjectContent)
try {
source.mkString
} finally {
source.close()
}
一旦你得到了来源,你可以从中做任何事情。如果它遵循.hocon文件格式,则使用TypeSafe配置进行解析,或者根据文件的任何格式进行解析
如果它遵循.hocon符号,您可以像
import com.typesafe.config.{Config, ConfigFactory}
val rawConfig: Config = ConfigFactory.parseString(contents)
您可以这样做:
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain
import com.amazonaws.services.s3.model.S3Object
import com.amazonaws.services.s3.{AmazonS3Client, AmazonS3URI}
import scala.io.{BufferedSource, Source}
val credentialsProvider = new DefaultAWSCredentialsProviderChain()
val s3Client = new AmazonS3Client(credentialsProvider)
val uri: AmazonS3URI = new AmazonS3URI(filePath)
val s3Object: S3Object = s3Client.getObject(uri.getBucket, uri.getKey)
val source: BufferedSource = Source.fromInputStream(s3Object.getObjectContent)
try {
source.mkString
} finally {
source.close()
}
一旦你得到了来源,你可以从中做任何事情。如果它遵循.hocon文件格式,则使用TypeSafe配置进行解析,或者根据文件的任何格式进行解析
如果它遵循.hocon符号,您可以像
import com.typesafe.config.{Config, ConfigFactory}
val rawConfig: Config = ConfigFactory.parseString(contents)
从S3中读取文件内容,就像在S3中读取任何其他文件一样。从该内容字符串读取属性,就像对任何字符串一样。如果您需要更多帮助,请在付出一些努力后显示一些代码。我会尝试从S3读取文件内容,就像您在S3中读取任何其他文件一样。从该内容字符串读取属性,就像对任何字符串一样。如果您需要更多帮助,请在付出一些努力后显示一些代码。我将尝试从