Loading

Monday, August 22, 2011

Get file info

Example of getting file info, such as path, last modified Date Time.



Get file info



package com.exercise.AndroidFile;



import java.io.File;

import java.util.Date;



import android.app.Activity;

import android.os.Bundle;

import android.widget.TextView;



public class AndroidFileActivity extends Activity {



/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);



TextView info = (TextView)findViewById(R.id.info);



File file = new File("/sdcard/test.txt");



String AbsolutePath = file.getAbsolutePath();

String Path = file.getPath();

String Parent = file.getParent();

String Name = file.getName();

long lastModified = file.lastModified();

Date lastModifiedDate = new Date(lastModified);



info.setText(

"AbsolutePath: " + AbsolutePath + "\n" +

"Path: " + Path + "\n" +

"Parent: " + Parent + "\n" +

"Name: " + Name + "\n" +

"lastModified: " + lastModified + "\n" +

"lastModifiedDate: " + lastModifiedDate

);



}

}








SHARE TWEET

Thank you for reading this article Get file info With URL http://x-tutorials.blogspot.com/2011/08/get-file-info.html. Also a time to read the other articles.

0 comments:

Write your comment for this article Get file info above!