i can read the next line in a file stored in the assets folder.
But how do read the previous line by click of a button.
my file is stored in the assets folder
if you got a small size file, just read all previous lines starting from the first line to the line you can read or even to the last line , split them by "\n" and get the previous line by its index, this is not a good way, however i recommend you to post your code so we can help you better ^_*
Related
I wanted to read and write specific lines from a CSV file.
Here is an example of my CSV
ID; Code; Name
1; ABHD; Paul
2; HYDR; Arthur
3; POAJ; Jake
4; PLMH; Georges
Actually I know how to read all the file and put it into a list of lines by myFile.readLines().
But I want to read a specific line like the line with the Code ABHD, and later on modify that specific Line without reading and writing the whole file. Any idea ?
Thanks by advance.
A CSV file is a not a database. You can't write individual elements inside the file. You need to read the entire file and write the entire file. If the file is a reasonable size, you can read the entire file into memory, alter the data you want to change (in memory) and then write the entire file again. If the file is huge, you probably need to make your modifications "on the fly" (ie: read a line, (optionally) change it, write the line to the output file).
There are libraries that you can use to parse the data, as CSV can be complicated to parse (especially if it contains text strings).
See https://www.baeldung.com/kotlin/csv-files for some help or search for "kotlin csv parse"
I want to print the source code, Opened File-> Print.
In the print its printing the full file path on top. I want to print only the file name. How can I do this?
The Text line $FILE$ is printing the file path on top of the paper. I tried $NAME$,$FILENAME$, etc,. but not working? Any hope?
You can print the file name with $FILENAME$, Check IntelliJ IDEA documentation here.
Text line :- In this text box, specify the contents of the header or footer. If necessary, combine plain text with print keywords. By default, IntelliJ IDEA suggests to print the name of a file $FILE$ in the header and the current page number $PAGE$ of all pages $TOTALPAGES$ in the footer.
The following print keywords are recognized:
$FILE$ prints fully qualified file name.
$PAGE$
$DATE$
$TIME$
$FILENAME$ prints file name without path.
$TOTALPAGES$
I am trying to create a PDF in my Android application using the Android PDF Writer. This is a very basic library that allows to create simple PDF files. It works quite well, but there is one thing I do not understand:
When I look at the generated PDF source code I can see, that the file starts with the following lines:
%PDF-1.4
%©»ªµ
1 0 obj
<<
/Type /Catalog
/Pages 2 0 R
>>
endobj
...
What does the second line mean? I searched a lot of different PDF syntax documentations but I have found no hint what that line could mean. In all examples I found the the %PDF-VersionXY line is directly followed by the first object / the catalog.
I am not sure if this is valid PDF code at all, or if this some an error due to some charset/enconding problem with the libraries source code.
Any idea what this could be about? What information could be included at this place and is %©»ªµ valid PDF or some enconding error?**
When taking a look at the pdf-1.4 reference here (or also in the current 1.7 here) in section 3.4.1 it says
Note: If a PDF file contains binary data, as most do (see Section 3.1, “Lexical Conventions”),
it is recommended that the header line be immediately followed by a
comment line containing at least four binary characters—that is, characters whose
codes are 128 or greater. This will ensure proper behavior of file transfer applications
that inspect data near the beginning of a file to determine whether to treat the file’s
contents as text or as binary.
So your generator seems to include this additional comment-line by default, even if there is no binary data to follow. What's in there doesn't matter as long as each byte value is > 128 (that is: outside the ASCII-range). In your case it's hex values A9 BB AA B5, so everything is fine and you don't have to worry about this line.
I am really lost here, i am trying to find my way around xml parsing, reading and writing.
I have this app where at one point i can input data such as a Date and a time for instance - click save, and once it saved it will write into an existing XML file, for later reading, and add it at the end in a format like this:
<Units>
<item>
<date>27-5-12</date>
<time>15:30</time>
</item>
<item>
... and so on ...
</Units>
i managed to read an xml file, but i am really having trouble in opening a premade - existing file for reading or writing.
currently i tried this code:
InputStream raw = this.getAssets().open("mydata.xml");
Reader is = new BufferedReader(new InputStreamReader(raw, "UTF8"));
which returns file not found exception.
could anyone direct me on what i should look for?
Thanks.
As written, your source XML file is located in your APK's assets directory - everything in your APK is read-only, so you won't be able to write to that file. (Also, you should probably put that XML data into the res/xml directory instead of the assets directory, unless you have a compelling reason to do otherwise.)
If the XML file isn't very long/complex, you could read the assets file into a structure, then add your new data to that structure, and write a new XML file into your app's data directory with the updated data. This approach has the advantage that you can have multiple source files feeding into one main file per app.
A more flexible and open-ended option would be to set up a database table. When the app is first installed, you load/update the table with data from the assets file. As your app keeps adding timestamped data, you just add new rows to the table. This approach also has the advantage that you can easily update the source data or the database structure with each app update - it's harder to compare old vs new data if it's stored internally in XML format.
I didn't see the assets folder in my project, i placed my xml file there and it works now :)
I have been working on android for about 4 months, i am working on a simple application to download a xml file placed on local server to the sdcard. I have done this part successfully, now i want to edit the data present in that xml. To get a more clear picture here is a sample code of my xml file ...
<seekbar>
<value>
50
</value>
</seekbar>
now am reading the value 50 by xml parsing and updating the value of seekbar as 50. Nowi change the value of seekbar to 100 through GUI. So when i click on save button i want that the value 50 should be replaced by 100 in the xml present in the sdcard. I have learnt about the sdcard permission but i am not getting about how to go for this modifying part.. Will i have to parse the whole xml again...??? Please help guys....
You can load the xml into a DOM Object. modify the value or value node and write the new DOM object back to the file.