1

私はファイルを持っています

String filename="MEMS.backup";

これを使用して保存します:

InputStream myInput;

         File sdCard = Environment.getExternalStorageDirectory();
         File directory = new File (sdCard, "Myfolder"); 

            try {


 myInput = new FileInputStream(MyApplication.getAppContext().getFilesDir().getParentFile().getPath()+"/databases/MEMS");

                // Create the folder if it doesn't exist:
                if (!directory.exists()) 
                {
                    directory.mkdirs();
                } 

    OutputStream myOutput = new FileOutputStream(directory.getPath()+
                         filename);

そしてこれをロードします:

OutputStream myOutput;

        File sdCard = Environment.getExternalStorageDirectory();
        File directory = new File (sdCard, "Myfolder");


        try {

myOutput= new FileOutputStream(MyApplication.getAppContext().getFilesDir().getParentFile().getPath()+"/databases/MEMS");

InputStream myInputs = new FileInputStream(directory.getPath()+filename);

問題は、sdcard に「Myfolder」を作成するが、空であることです。

そして、ファイル「MEMS」はsdcardに入れられます(Myfolderにあるはずです)。

また、ファイルの名前は MEMS ではなく MyfolderMEMS です。

私は自分の間違いを理解できません。

4

3 に答える 3

1

変化する

 OutputStream myOutput = new FileOutputStream(directory.getPath()+
                         filename);

File file = new File(directory, filename); 
OutputStream myOutput = new FileOutputStream(file);
于 2013-06-07T08:52:38.377 に答える
1

myfolder に新しいファイルを作成するには、以下のコードを参照してください

 File sdCard = Environment.getExternalStorageDirectory();
 File directory = new File (sdCard, "Myfolder"); 


if( !directory.exists() )
    directory.mkdirs();

File f = new File( directory, "my_file.jpg" );
OutputStream myOutput = new FileOutputStream(f);
于 2013-06-07T09:02:54.953 に答える
1

問題がファイルセパレーターが見つからないことを願っています。これを試してください。

OutputStream myOutput = new FileOutputStream(directory.getPath()+File.separator+
                         filename);

またはこれで試してください、

OutputStream myOutput = new FileOutputStream(directory.getPath()+"/"+
                         filename);
于 2013-06-07T08:56:49.483 に答える