android-Java中实现删除文件 - 随心

package com.tware.pdfdrop;


import java.io.File;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;


public class PdfDropActivity extends Activity{
    /** Called when the activity is first created. */
TextView textview;

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
 
        textview = (TextView)findViewById(R.id.v_file_list);


        View clsbtn = findViewById(R.id.btn_clean);
        clsbtn.setOnClickListener(new OnClickListener(){
        public void onClick(View v)
        {


        File f = new File("/sdcard");
       
        File[] fl = f.listFiles();
        for (int i=0; i         {
        if(fl[i].toString().endsWith(".pdf") || fl[i].toString().endsWith(".PDF"))
        {
        if(fl[i].delete())
{
textview.setTextSize(20);
textview.setTextColor(Color.GREEN);
textview.append("\n" + fl[i].toString()+ "--- Success");
}else{
textview.setTextSize(20);
textview.setTextColor(Color.RED);
textview.append("\n" + fl[i].toString()+ "--- Failed");
}
        }
        }
        }
        });
    }

}


转自:http://blog.csdn.net/tody_guo/article/details/6646712

你可能感兴趣的:(android)