我試圖與該代碼 文件複製行動,但它給了我一個錯誤語法錯誤,插入「}」來完成ClassBody MainActivity文件複製操作的Android
在這裏我把的地方* * 幫我請
package com.AleXMan.taptaprevenge4songinstaller;
import java.io.File;
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;
}
}
如果你給我一個代碼,比我的更好,或者給我的這個錯誤的幫助,我將是你非常感謝!
替換爲}}); – StarsSky 2013-02-09 16:38:31