0

Possible Duplicate:
Java - Convert number to string

private String getHome() {
    String defaultHome = Environment.getExternalStorageDirectory().getAbsolutePath(); 

    File f = new File("/sdcard/download");

    File[] files = f.listFiles();

   for(int i=0; i < files.length; i++)
    {
        File file = files[i];
        //take the file name only
    long size = file.length()/1024;
    String path = file.getPath().substring(file.getPath().lastIndexOf("/")+1,file.getPath().length()).toLowerCase(); 
    String newString = size.toString();



    //String path = getSharedPreferences(PREF_TAG, 0).getString(PREF_HOME,defaultHome);
    //if (path.length()>1 && path.endsWith("/")) {
    //  path = path.substring(0,path.length()-2);
    //}


    //File pathFile = new File(path);

    if (file.exists() && file.isDirectory())
        return path+size;
    else
        return defaultHome+size;
    }
   return defaultHome;
}
Community
  • 1
  • 1
BobDroid
  • 1,898
  • 5
  • 19
  • 39
  • Well, *is* it possible? What have you tried? Did it work? If not, why not? –  Dec 29 '11 at 07:26
  • http://stackoverflow.com/questions/2563608/check-whether-a-string-is-parsable-into-long-without-try-catch , http://stackoverflow.com/questions/4121923/i-cant-convert-string-to-int , http://stackoverflow.com/questions/653990/what-is-the-most-efficient-way-to-convert-an-int-to-a-string , http://stackoverflow.com/questions/5585779/converting-string-to-int-in-java , http://stackoverflow.com/questions/7604379/is-using-int-bad-for-converting-java-ints-to-strings –  Dec 29 '11 at 07:29
  • The related questions have to do with "int", but it's the *exact same thing*. Consider that 99% of the post is *irrelevant* to actually answering the question. Only include what is relevant: I can't even see *which* part needs the conversions. –  Dec 29 '11 at 07:31

3 Answers3

1

You may convert value of long type to String type using String.valueOf() or Long.toString() method.

String str1=String.valueOf(long_var);
String str2=Long.toString(long_var);
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
1
long size = f.length()/1024;
String s = String.valueOf(size); 
0

You can do something like this

String newString  = String.valueOf(size);

or simply u can do String newString = size+"";

See for the doc in this link

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
Hussain
  • 5,552
  • 4
  • 40
  • 50