I have a text file "test.txt" under the Resources, and a function "parseSth(char* str)" in the "util.cpp" to read the "test.txt" do something.
However, if I use like this parseSth("text.txt"), the ios and android all cannot find the file. And use parseSth(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("text.txt")) will work fine on ios, but cannot find the path.
Why? How I can do?
I suppose that your file is embedded into APK file on Android and thus doesn't have a path to it per-se.
Use the following function to extract data from the file (it automatically handles apk/sd card differences).
FileUtils::getInstance()->getDataFromFile(filename)
Related
I've got c++ code in which I try to get a file from a directory on an android device. I've tried different ways to set the path which I pass to the fopen() function like:
/Android/data/com.myapp/files/Blip.wav
There actually is this file. But I guess that this is not a proper way to write a path. (The example was obtained by the java code )
getContext().getApplicationContext().getFilesDir().getPath() + "/Blip.wav"
There actually is this file
Since I have never seen an Android device with an /Android directory, that is unlikely.
What would fit is if you are looking at /Android/data/com.myapp/files/Blip.wav in a desktop file manager, using a USB or similar connection. In that case, Android/data/com.myapp/files/Blip.wav is a relative path in external storage. Specifically, it maps to:
new File(getContext().getExternalFilesDir(), "Blip.wav")
Try using this.
File root=Environment.getExternalStorageDirectory();
File file=new File(root,"/PersonData/Blip.wav");
Here personData is the name of folder
I was working with dropbox sync api on android platform, all seems to work smoothly except following case:
When i upload a file on dropbox which has no extension, then a call to listFolder(dbxPath) does not return file that had no extension.
I am uploading file through Linux platform, e.g A filename XYZ which is text file on linux.
but when i changing the filename of the same file to XYZ.txt, then, listFolder(dbxPath) returns the info about file.
It would be nice if someone explain this behavior, and possible solution too (as dropbox application is able to show XYZ file).
Moving this to an answer... the issue is that you have "documents" permission, and that doesn't include extensionless files.
See https://www.dropbox.com/developers/reference/devguide#app-permissions for the full list of file extensions supported by each file type.
I have a short question about writing to a file in android. I am writing a game where I use a xml file to save some data about the level stats. Now I have seen that if I save this xml file in AssetManager it is not possible to change it (only permissions to read files).
Now because I can only modify files which are in the filesystem of android (using openFileInput and openFileOutput to work with it) I wonder where I have to save my (already existing) xml file in my eclipse project so that I can use openFileInput to load it and change it via code.
Do I have to make a new folder? E.g. project_path/files/myxml.xml.
Is it even possible to load a file which was created (outside the AssetManager folder) before installing the .apk to target?
If it is possible does anybody have some example code?
I hope you understand my question.
There is no such place. Installation of android apps does not include an automatic step that would copy your content from apk to the internal folder (and your application does not reside in the folder either).
You will have to create your XML file in code, possibly checking for its existence before each access (or using some other marker).
I have an android application I am developing in Java.
I need it to load a text file so it can read what is in the text file and get values from it.
However, everything I have read so far has been directing me to use resources and package it up with the application.
However this means if I want to change the text file, I have to reinstall the application, which is not what I want.
I need to end up with the .apk file and the .txt file in the same folder on my android phone so I can change the .txt file and the app reads in the text file in its directory.
Can anyone help?
No, you do not want to end up with the .apk and the .txt file in the same folder.
You want to end up with the .txt in some place that's always the same and that you know about.
You can deploy the initial .txt via the ressources (aka: package it and copy it to the sd for example) and later download a new version (or copy something to the device via usb).
Then inside your app check if the file exists and open it with standard Java. There's plenty of source around for that.
I have an app that uses native code to generate a .pcap file (amongst other things). The idea is that while running the program, the pcap file is created and I can later retrieve it by say plugging in the phone into my laptop and then access it.
I use fopen(), fwrite() and fclose() in my native code to create the .pcap file. My question is, how should I specify the filename and filepath? For example, when I run it on windows, I just use "test.pcap" and it generates it in the same folder, but how does this work on android? As I mentioned before, the file is created down in native level.
Native or not, the directory structure should be the same.
You can create a directory in /flash called pcap. But check it exists first, as it can be /nand. Use /sdcard if you want to write in the SD card.
After that you can use, say, /flash/pcap/test.pcap as path for the file. The file would be created in the internal flash memory.