Android Tutorial Text files

rworner

Member
Licensed User
Longtime User
I am developing for a rooted MK802 mini PC. I have created a local.prop file that I can manually instal via a file manager, but want to automate the process using the code below.

WhenI run this I get the following error:
FileNotFoundException: /data/local.prop open failed EACCES (Permission Denied)
-----------------------------

Sub Globals
Dim tw As TextWriter
End Sub
Sub Activity_Create(FirstTime As Boolean)

Dim s1, sr1, sr2, sr3 As String
s1="local.prop"
sr1="service.adb.tcp.port=5555"
sr2="ro.kernel.android.bootanim=0"
sr3="debug.sf.nobootanimation=1"
If File.Exists("/data/",s1)= False Then
tw.Initialize(File.OpenOutput("/data/",s1,False))
tw.WriteLine(sr1)
tw.WriteLine(sr2)
tw.WriteLine(sr3)
tw.Close
End If
End Sub
 

eps

Expert
Licensed User
Longtime User
Ideally you should start a new thread for a Q like this, but to try and help the problem is the location of the file, you need
to tell it where it is, it should be located under the directories that form part of your App, such as :

B4X:
TextWriteLine.Initialize(File.OpenOutput(File.DirInternal, "yourfile.txt", False))

I think it would be best to use the DirInternal, then prepend the /data/ part to your file name..

HTH
 

rworner

Member
Licensed User
Longtime User
Tr

I tried the suggestion, no luck.
I also tried a SU account --but instead of creating /data/local.prop it created /<packagename>/local.prop

Sub Activity_Create(FirstTime As Boolean)

Dim Command, Runner As String
Dim StdOut, StdErr As StringBuilder
Dim Result As Int
Dim Ph As Phone
StdOut.Initialize
StdErr.Initialize
Runner = File.Combine(File.DirInternal, "runner")
Command = File.Combine(File.DirInternal, "command")
File.WriteString(File.DirInternalCache, "runner", "su < " & Command)
File.WriteString(File.DirInternalCache, "command", "echo service.adb.tcp.port=5555 >> /data/local.prop" & CRLF & "exit") 'Any commands via crlf, and exit at end
Result = Ph.Shell("sh", Array As String(Runner), StdOut, StdErr)
Log("Result: " & Result)
Runner = File.Combine(File.DirInternal, "runner")
Command = File.Combine(File.DirInternal, "command")
File.WriteString(File.DirInternalCache, "runner", "su < " & Command)
File.WriteString(File.DirInternalCache, "command", "echo ro.kernel.android.bootanim=0 >> /data/local.prop" & CRLF & "exit") 'Any commands via crlf, and exit at end
Result = Ph.Shell("sh", Array As String(Runner), StdOut, StdErr)
Log("Result: " & Result)
Runner = File.Combine(File.DirInternal, "runner")
Command = File.Combine(File.DirInternal, "command")
File.WriteString(File.DirInternalCache, "runner", "su < " & Command)
File.WriteString(File.DirInternalCache, "command", "echo debug.sf.nobootanimation=1 >> /data/local.prop" & CRLF & "exit") 'Any commands via crlf, and exit at end
Result = Ph.Shell("sh", Array As String(Runner), StdOut, StdErr)
Log("Result: " & Result)
End Sub
 

eps

Expert
Licensed User
Longtime User
I can't see in your code where it carries out the FileOpen part...??

Can you enclose the above in
"[ code ]"

"[ /code ]"

tags please?
 

djveleno

Active Member
Licensed User
Longtime User
Hi Klaus,
I created an app that has many pictures in different folders, how can I load images from these folders?
I used this code, but it does not work:
B4X:
ImageView1.Bitmap = LoadBitmap(File.DirAssets &/"automibili", ImageFiles(0))
Thanks for all.
 

klaus

Expert
Licensed User
Longtime User
Unfortunately you don't give enough information to help you !
What have you done, don't you have a project showing the problem.
What doesn't work ?
Do you get any error messages ?
Does the folder File.DirAssets &/"automibili" exist ?
What is ImageFiles(0) and how is it defined ?
Well, it's almost impossible to help whithout knowing the answeres to these questions !
The best way : post your project as a zip file (IDE menu File / Export As Zip) so we could see what you have done and how and test your project in the same conditions as you do.

Best regards.
 

dieterp

Active Member
Licensed User
Longtime User
I use a List to store a recordset using the DBUtils.ExecuteMemoryTable function. When I use File.WriteList to write that List to a text file, it writes the actual arraytype ([Ljava.lang.String;@42397b68) and not the entries I retrieve from the database. Is it possible to write a recordset that would have several rows containing Name, Surname, Age etc. values to a text file?
 

IslamQabel

Active Member
Licensed User
Longtime User
Thanks Erel, very helpful......So i made a code that i can read the help from a files stored in "Files" folder instead typing a very long help in Msgbox..
B4X:
sub Activity_Create

Activity.AddMenuItem("HELP","MenuHelp")
End Sub


Sub MenuHelp_click
    Msgbox(File.ReadString(File.DirAssets, "help.txt"), "Help")
End Sub

Can i display the contents of a txt file in Msgbox with different color , different font and change the color of background ?
 

Kwame Twum

Active Member
Licensed User
Longtime User
Please guys, how do you read a text file from a remote computer/server?
 

agus mulyana

Member
Licensed User
Longtime User
Dear all

Execuse me, I want to open an EXCEL file (ex: boox1 from SD Card) , anyone can help me ? or give me a free sample/code for this ? thank you
 

schemer

Active Member
Licensed User
Longtime User
I have found this page and am trying to test it for saving a text file. The demo from page one seems to work until it gets to the last two subroutines and the screen goes blank. What is supposed to happen there and how do I access the file on my device? Here are the last two subs:

B4X:
Sub WriteTextWriter
    Dim TextWriter1 As TextWriter
    TextWriter1.Initialize(File.OpenOutput(File.DirRootExternal, "Text.txt", False))
    For i = 1 To 10
        TextWriter1.WriteLine("Line" & i)
    Next
    TextWriter1.Close
End Sub

Sub ReadTextReader
    Dim TextReader1 As TextReader
    TextReader1.Initialize(File.OpenInput(File.DirRootExternal, "Text.txt"))
    Dim line As String
    line = TextReader1.ReadLine  
    Do While line <> Null
        Log(line) 'write the line to LogCat
        line = TextReader1.ReadLine
    Loop
    TextReader1.Close
End Sub

Thanks,
schemer

edit: I think I see the answer: 'write the line to LogCat
 

schemer

Active Member
Licensed User
Longtime User
Note that in most cases there is no reason to use TextReader and TextWriter. You should instead use File.WriteString or WriteList (and ReadString, ReadList).

Thank you Erel for the added info. I will do some more studying. My Nexus 7 arrives today so I will have a dedicated test device. WooHoo!
schemer
 

haddad

Member
Licensed User
Longtime User
hi all
i have a problemme i can write in a file txt but can't read it , may i have a permission for reading or what ?

cordialement
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…