以下のプログラムでは、以下に示すように例外が発生します。基本的に私がやろうとしているのは、リモートシステムからデバイスにファイルをコピーすることですが、エミュレータとデバイスの両方でメモリカードに保存するときに、以下の例外はエミュレータからのもので、メモリカードがエミュレータに接続されていないため例外であると言えますが、コードは物理デバイスで機能します。
エミュレーターとデバイスでコードを動作させる方法
例外:
 09-13 15:47:16.789: I/System.out(400): java.io.FileNotFoundException: /mnt/sdcard/Download/new.txt (Not a directory)
コード:
package com.scp2;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import com.jcraft.jsch.*;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.widget.Toast;
public class Scp2Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
            JSch jsch = new JSch();
            Session session = null;
            try {
                session = jsch.getSession("guest", "17.30.5.2", 22);
                session.connect();
                Toast.makeText(this,  "in try2" , Toast.LENGTH_SHORT).show();
                channel.connect();
                ChannelSftp sftpChannel = (ChannelSftp) channel;
                File ofile = new File(Environment.getExternalStoragePublicDirectory (Environment.DIRECTORY_DOWNLOADS),"new.txt");
                Toast.makeText(this, ofile.toString() , Toast.LENGTH_SHORT).show();
                                   try {
                    FileOutputStream f = new FileOutputStream(ofile);
                  sftpChannel.get("/root/a.txt","/mnt/sdcard/download/dd.txt");
                  /*OR What shoud the abobe statement be **/
              //sftpChannel.get("/root/a.txt",ofile); or this statement is correct
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                         System.out.println(e.toString());
                }
                sftpChannel.exit();
                session.disconnect();
            } catch (JSchException e) {
                e.printStackTrace(); 
            } catch (SftpException e) {
                e.printStackTrace();
            }
    }
 }