我正在尝试使用以下代码执行文件复制操作但它给了我一个错误语法错误,插入"}"以完成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;
}
}
如果你给我一个比我的代码更好的代码,或者帮我解决这个错误,我将非常感谢你!
更换线路**}**);
带}});
缩进所有代码是一种最佳做法。在Eclipse中,选择所有行(CTRL+A),然后CTRL+SHIFT+F所有代码都将是清晰和缩进的,因此很容易找出问题所在。