title: java.io.FileNotFoundException while accessing from S3 bucket?
body: <p>I am doing a small POC in AWS. I trying to read a csv file from S3 bucket and displaying in the CloudWatch log files . Everything is going fine but while accessing the file getting java.io.FileNotFoundException  </p>
  
  <p><strong>Coding</strong></p>
  
  <pre><code>public class LambdaFunctionHandler implements RequestHandler&lt;S3Event, Report&gt; {
  
  Region AWS_REGION = Region.getRegion(Regions.US_EAST_1);
  
  public Report handleRequest(S3Event s3event, Context context) {
      long startTime = System.currentTimeMillis();
      Report statusReport = new Report();
      LambdaLogger logger = context.getLogger();
  
      logger.log("Lambda Function Started");
      logger.log("I am inside lambda function");
      Helper helper = new Helper();
  
      try {
          logger.log("I am inside lambda function2");
          S3EventNotificationRecord record = s3event.getRecords().get(0);
          logger.log("I am inside lambda function3");
          String srcBucket = record.getS3().getBucket().getName();
          logger.log("I am inside lambda function4");
          // Object key may have spaces or unicode non-ASCII characters.
          String srcKey = record.getS3().getObject().getKey().replace('+', ' ');
          logger.log("I am inside lambda function5");
          srcKey = URLDecoder.decode(srcKey, "UTF-8");
          logger.log("I am inside lambda function6");
  
          AmazonS3 s3Client = new AmazonS3Client();
          logger.log("I am inside lambda function7");
          S3Object s3Object = s3Client.getObject(new GetObjectRequest(srcBucket, srcKey));
          logger.log("I am inside lambda function8");
          statusReport.setFileSize(s3Object.getObjectMetadata().getContentLength());
          logger.log("I am inside lambda function9");
  
          logger.log("S3 Event Received: " + srcBucket + "/" + srcKey);
          logger.log("I am inside lambda function10");
  
          File file = new File(srcBucket+"/"+srcKey);
          try {
              Scanner readData =new Scanner(file);
              while(readData.hasNext()) {
                  String data = readData.next();
                  logger.log("I am inside lambda function data ;;got it");
                  //System.out.println("data"+data);
              }
              readData.close();
          }catch(FileNotFoundException e){
              e.printStackTrace();
          }
  </code></pre>
  
  <p><strong>CloudWatch Log file output</strong></p>
  
  <p><a href="https://i.stack.imgur.com/LONge.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LONge.png" alt="enter image description here"></a></p>
  
  <p><strong>CloudWatch Log Errors</strong></p>
  
  <p>I am inside lambda function </p>
  
  <p>I am inside lambda function2 </p>
  
  <p>I am inside lambda function3 </p>
  
  <p>I am inside lambda function4</p>
  
  <p>I am inside lambda function5</p>
  
  <p>I am inside lambda function6</p>
  
  <p>I am inside lambda function7</p>
  
  <p>I am inside lambda function8</p>
  
  <p>I am inside lambda function9</p>
  
  <p>S3 Event Received: readfilefromcsvfile/def_nhtsa_crash_test.csv</p>
  
  <p>I am inside lambda function10</p>
  
  <p>java.io.FileNotFoundException: </p>
  
  <p>readfilefromcsvfile/def_nhtsa_crash_test.csv (No such file or directory)
  java.io.FileNotFoundException: readfilefromcsvfile/def_nhtsa_crash_test.csv (No such file or directory)
  at java.io.FileInputStream.open0(Native Method)</p>
  
  <p>If we will look into the log output it is telling that no such file, but I have kept it in S3 bucket. Can anyone tell me how to access S3 file in java ? or What is the path name I should give while accessing the S3 bucket file ?</p>