Read/write From FileSystem, browse Account
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;
import android.app.Activity;
import android.widget.ListView;
class AccountFileUtil {
public Properties readFromFS(Activity caller) {
try{
Properties fileProps = new Properties();
File dir = caller.getApplicationContext().getFilesDir();
File input = new File(dir.getAbsolutePath() + "/preferences" );
fileProps.load(new FileInputStream(input));
return fileProps;
}
catch(Exception e){}
return null;
}
public void writeFromFS(Activity caller){
try{
Properties props = new Properties();
props.put("clau","stronzo");
File dir = caller.getApplicationContext().getFilesDir();
File out = new File(dir.getPath() + "/preferences") ;
props.put("location" , dir.getAbsolutePath());
props.save(new FileOutputStream(out), null);
}
catch(Exception e){}
}
public ListView browseAccount(Activity caller){
ListView map = new ListView(null);
try{
File dir = caller.getApplicationContext().getFilesDir();
int i = 0;
Properties props = new Properties();
while ( true) {
props.load(new FileInputStream(dir.getAbsolutePath() + "/preferences" + i));
String account = (String)props.get("account");
//map.setite
i++;
}
}
catch(Exception e){}
return map;
}
}
Related examples in the same category