dchhetri
dchhetri

Reputation: 7136

Point to files inside the apk?

I'm using phonegap to develop an android application. In my javaclass I want to point to a file in the "assets/www/" directory, what would be the full path?

Upvotes: 0

Views: 185

Answers (2)

Amol Gupta
Amol Gupta

Reputation: 704

All the paths are relative to your project home directory. The project home directory is the root (/) and all the other paths are relative to this. This is not just the case with android but for all the java projects(as a matter of fact in most of the other languages too).

Upvotes: 0

CrackerJack9
CrackerJack9

Reputation: 3651

If you know the path, use getAssets().open(assetPath);

An example may be:

private static final int READ_EULA_BUFFER_SIZE = 1024;
private static final String FILE_PATH = "www/yourfile";

BufferedReader stream = new BufferedReader(new InputStreamReader(getAssets().open(FILE_PATH), BUFFER_SIZE);

String line;
StringBuilder buffer = new StringBuilder();
while ((line = stream.readLine()) != null) {
    buffer.append(line).append('\n');
}
return buffer;

Upvotes: 1

Related Questions