title: open failed: ENOENT (No such file or directory) internal storage
body: <p>I have a little bit of trouble finding my error in my Android application. </p>
  
  <p>The target of my "ResultActivity" is, to create a file in the internal storage and then download a file from my server (via FTP) and then call the next Activity (GiftActivity).</p>
  
  <p>But when the next Activity tries to access these files, I get the mentioned error. As far nothing new, but the interesting part is, that if I kill the application by hand and restart it, it works like a charm the next time.</p>
  
  <p>Here's my code:</p>
  
  <p><strong>ResultActivity.java:</strong></p>
  
  <pre><code>//...
  ImageButton download = (ImageButton) findViewById(R.id.downloadCode);
  download.setBackgroundDrawable(null);
  assert download != null;
  download.setOnClickListener(new View.OnClickListener() {@
    Override
    public void onClick(View v) {
      new AsyncTask &lt; Integer, Void, Void &gt; () {@
        Override
        protected Void doInBackground(Integer...params) {
          try {
            JSch jsch2 = new JSch();
  
            session = jsch2.getSession("xy", "1.2.3.4", 22);
            session.setPassword("xyz123");
            //Set FTP Settings
            java.util.Properties config = new java.util.Properties();
            config.put("StrictHostKeyChecking", "no");
            //Disables Fingerprint checking!
            session.setConfig(config);
            //load config to session
  
            session.connect();
  
            //connect to the session
            channel = session.openChannel("sftp");
            channel.connect();
            //open an SFTP Channel
            channelSftp = (ChannelSftp) channel;
  
            File checkExistance = getBaseContext().getFileStreamPath("code.txt");
            if (checkExistance.exists()) {
              getBaseContext().deleteFile("code.txt");
              getBaseContext().deleteFile("usage.txt");
            }
  
            File code = new File(getFilesDir().getAbsolutePath(), "code.txt");
            File usage = new File(getFilesDir().getAbsolutePath(), "usage.txt");
  
            code.createNewFile();
            usage.createNewFile();
  
            channelSftp.get("/home/code.txt", getFilesDir() + "/code.txt");
            channelSftp.get("/home/usage.txt", getFilesDir() + "/usage.txt");
          } catch (JSchException e) {
            e.printStackTrace();
          } catch (SftpException e) {
            e.printStackTrace();
          } catch (IOException e) {
            e.printStackTrace();
          }
          return null;
        }
      }.execute(1);
      Intent intent = new Intent(ResultActivity.this, GiftActivity.class);
      ResultActivity.this.startActivity(intent);
      ResultActivity.this.finish();
    }
  });
  </code></pre>
  
  <p><strong>GiftActivity.java:</strong></p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_gift);
  
          TextView actualCode = (TextView) findViewById(R.id.actualCode);
          TextView actualUsage = (TextView) findViewById(R.id.usageCode);
          String code = "";
          String usage = "";
  
          try {
  
              FileInputStream fis = getBaseContext().openFileInput("code.txt");
              InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
              BufferedReader bufferedReader = new BufferedReader(isr);
              StringBuilder sb = new StringBuilder();
              String line;
              while ((line = bufferedReader.readLine()) != null) {
                  sb.append(line).append("\n");
              }
              code = sb.toString();
          } catch (IOException e) {
              e.printStackTrace();
              code="error1";
          }
  
          try {
              FileInputStream fis = getBaseContext().openFileInput("usage.txt");
              InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
              BufferedReader bufferedReader = new BufferedReader(isr);
              StringBuilder sb = new StringBuilder();
              String line;
              while ((line = bufferedReader.readLine()) != null) {
                  sb.append(line).append("\n");
              }
              usage = sb.toString();
          } catch (IOException e) {
          e.printStackTrace();
          usage="error2";
          }
          actualCode.setText(code);
          actualUsage.setText("you got a gift for " + usage + " congratulation!");
      }
  </code></pre>