-2

i've searched alot but nothing solves my problem. i want to build an app which reads html files from tab's internal folder. the path of html files is /file manager/device storage/Android/data/K1.html.
The problem is that the number of web pages may increase or decrease by user and i want to build the functionality that app can read all the webpages placed in that folder. i used following code for reading file from internal storage but it doesn't point to the path. I know it is not difficult please guide me how to obtain this functionality, thanks in advance.

File tabFolder = getFilesDir();
String root = tabFolder.toString();
File myFile = new File(root + "/Android/data/K1.html");
    if(myFile.exists()){
    Toast.makeText(MainActivity.this, "exists", Toast.LENGTH_SHORT).show();

    }
    else{
        Toast.makeText(MainActivity.this, "does not exists", Toast.LENGTH_SHORT).show();
    } 
konain ali
  • 37
  • 1
  • 10

1 Answers1

1

try now...

String fileName = "K1.html";
String content = "K1 html file content here";
FileOutputStream outputStream = null;
try {
outputStream = openFileOutput(fileName, Context.MODE_PRIVATE);
outputStream.write(content.getBytes());
outputStream.close();
} catch (Exception e) {
e.printStackTrace();}

String path=getApplicationContext().getFilesDir().getAbsolutePath()+"/K1.html";
File file = new File ( path ); 
if ( file.exists() ) 
{
 // Toast File is exists
}
else
{
 // Toast File is not exists
}
Rohit Goswami
  • 617
  • 5
  • 17