2017년 4월 15일 토요일

Having issues with saving and retrieving files


I am working on simple app to store statistics.  I want to be able to save a file, etc..  However, ever time I try to access the file it is giving me either a 2101 or 2001 error.  I am using a Galaxy S6, which does not have an sd port.  I wasn't sure if that was the issue or just my code.  Any help would be greatly appreciated.  

--
do you get issues while saving the file or while reading the file?
according to the documentation http://ai2.appinventor.mit.edu/reference/components/storage.html#File, the AppendToFile method should also work in case the file does not exist

AppendToFile(text text, text fileName)
Appends text to the end of a file. Creates the file if it does not already exist. See the help text under SaveFile for information about where files are written.

usually you would use a file name with extension, for example SteveMarquette.txt ...
what happens, if you use the SaveFile method?

--
I cannot find the file on my device.  That is why I was wondering if you could save on a device without an SD port.  
I have tried both the Save and Append command, in either case I cannot find the file, even when I search I my phone manually. 

Ideas?

--
see again the documentation: 
http://ai2.appinventor.mit.edu/reference/components/storage.html#File
you are using a filename without slash, which means, you store the file in the private data directory, however if you test using the companion app you should be able to find the file


SaveFile(text text, text fileName)
Saves text to a file. If the filename begins with a slash (/) the file is written to the sdcard (for example, writing to /myFile.txt will write the file to /sdcard/myFile.txt). If the filename does not start with a slash, it will be written in the program's private data directory where it will not be accessible to other programs on the phone. There is a special exception for the AI Companion where these files are written to /sdcard/AppInventor/data to facilitate debugging. Note that this block will overwrite a file if it already exists. If you want to add content to a file use the append block.

--
I notice the given blocks don't add a ".txt"  suffix to the file name.
On Windows, the suffix is used to pick program associations.
Is that a problem for Android and AI2, besides being poor practice?

--
Having same problem I would like to save text to a picture but you are able to text your own message any ideas?


--
@Lieb: you have a completely different question...

to write text onto a picture you have to use a canvas, display the picture as canvas background image and use one of the DrawText methods to write the text, then save the canvas (which is the picture including the text)

--
I can write text to the picture i just cant get it to save, sorry

--
protip: it helps to provide a screenshot, else we do not know, what the problem might be...


--
So, I have been trying different ways to get my program to work.  I have been using both my mobile and a tablet (neither of which have an SD card).  I'm not sure if it is saving my file.  I do not get an error unless I try to share the file and it will say file not found.  I have tried many different combinations of the file names from the documentation, but I must be missing something.  I have attached one attempt.  Not sure where to go from here.  I have read the documentation on sharing and saving files, but thank you for the suggestion.  


--
 I have been using both my mobile and a tablet (neither of which have an SD card).
you are storing in the internat sdcard...

the correct path for the Sharing component is file:///mnt/sdcard/SteveMarquette.txt

--

댓글 없음:

댓글 쓰기