文件复制动作android

时间:2013-02-09 16:35:58

标签: android file copy action directory

我正在尝试使用此代码进行文件复制操作 但它给我一个错误语法错误,插入“}”来完成ClassBody MainActivity

在我放 * *的地方 请帮帮我

package com.AleXMan.taptaprevenge4songinstaller;

import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream;

import android.media.MediaCryptoException; import android.os.Bundle; import android.os.Environment; import android.app.Activity; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);






                Button button1 = (Button) findViewById(R.id.button1);
                button1.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {


                        File srcFolder = new File(Environment.getExternalStorageDirectory()+"/folder");
                        File destFolder = new File("/data/data/folder");

                        try{

                            if(!srcFolder.exists()){

                                    Log.e("Error","Folder does not exist");
                                   //just exit

                                }
                            else
                                {

                                    InputStream in = new FileInputStream(srcFolder);

                                    OutputStream out = new FileOutputStream(destFolder);

                                    // Copy the bits from instream to outstream
                                    byte[] buf = new byte[1024];
                                    int len;
                                    while ((len = in.read(buf)) > 0) {
                                        out.write(buf, 0, len);
                                    }
                                    in.close();
                                    out.close();

                                }

                            }

                        finally{

                                }

                    **}**);


}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

}

如果你给我一个比我更好的代码,或者给我一个这个错误的帮助,我将非常感谢你!

1 个答案:

答案 0 :(得分:0)

替换您的专线**}**);

}});

缩进所有代码是最佳做法。在Eclipse中,选择所有行( CTRL + A )然后 CTRL + SHIFT + F 所有代码都将清晰并缩进,因此很容易找到问题的位置和问题是