I want to store data in android application date wise, i.e different data for different day. The data will be just integer values and meanwhile want to retrieve it date wise only. i want to store it in a single file. and then want to display it in a chart format in android datewise.. so is there any way i can do it. or can anyone guide me.
Thanks
You can have a look on SQLite Storage.if you want store it in table format. Which can store the values in table format and it will be easy for you to retrive. I think this is the best option.
Assuming below are file contents.
Read all contents of file in StringBuffer and then get daywise contents by spliting based on
"-------EOD----". This will return daywise text.
12/02/2014 1111222222222
-------EOD----
11/02/2014 1111222222222
-------EOD----
10/02/2014 1111222222222
-------EOD----
Related
I need some suggestions for the App am developing,
I have some 6 sensors which are continuously sending the data to the App, I need to log the data in some file. I want to know which is the better approach to store such data. I tired using json by storing all the values in one json objects, and created a array of json objects somewhat like this
[{sensor1, senor2, sensor3, sensor4, sensor5, sensor6},{sensor1, senor2, sensor3, sensor4, sensor5, sensor6}]
But I have more then 20000 data like this to store, creating the array of 20000 json object and writing to file in one shot looks expensive. on that data is coming once in 15 seconds. writing one JSON object once in every 15 second will disturb the JSON format.
So I need suggestion like is using JSON method to store this data is better or I should think of some other method like CSV??
If you want to store the data points over time, have you considered using a time series database? There are various NoSQL style databases that are well suited to this task, Cassandra being one
https://academy.datastax.com/demos/getting-started-time-series-data-modeling
Without a doubt, CSV.
But only if you're certain your format will not change (always 6 sensors). Furthermore, in CSV, data can be added at the end of a file while in JSON you have to write in the middle.
I display dates to the user in a layout that are let's say are textual.
When the user presses a button I want to get the information in those fields that represent these "dates" but if I get the text in them is not of value to me.
I would need to store somewhere the original dates that created these "textual" elements and fetch them from there.
Is there a specific construct in android that one can use as a stash area or should I just use a static class with variable to hold them?
In your case, you should use SharedPreferences to store the data by converting it into a String (text) or int/long first.
This will allow you to easily write and retrieve data, and you should use this.
You can also use the file system to save almost any Java object using serializable, on Internal Storage.
Either way, the data will stay there even if your app is closed or the device is turned off.
In my software I want to store some data, that later they will be used. Something like a database to hold data:
Date, source path, destination path, and an array of file names.
Also another table to hold information about ftp connection:
Host, port, username and password
I need to know what methods are available to store and parse these data. I noticed there is a file type called .csv, is this an option for me? And is there any other option?
I think this depends a lot on how much data you want to store and how you need to access it.
If your application is going to be collecting a lot of structured data, such as user profiles, or product information, ie, if your application is all about a database then, yes as others have commented some sort of SQL database would make sense.
If your needs are more along the lines of just storing some "session" information, maybe like the last state of a GUI form for example, you might want to just serialize the data and write it to a simple text file.
One simple way to do that would be to serialize the data in a human readable format such as JSON and then write the text to a file, and then read it back and deserialize it when you need to restore it from storage.
If this is what you are looking for take a look at gson (from google), it provides a very easy what to convert a java object to JSON and back again.
JSON, is just text, so you can just read and write it to a simple text file.
I have a problem in create program which reading the text-file in particular manner.
A text-file which have data in below format.
Id|Name|City
1|Mack|London
And another text-file which contain name & age like,
Name|Age
Mack|31
Now I want to find out all data who's city is London and age is 31.
How to get it?
I don't see why you dont use a database. The files you use, the delimiters etc, they are the main reason why databases are created. And what you asked is a simple JOIN operation. If you insist on using files instead of database, you need a long algorithm for that operation which is predefined in SQL language.
I want to make a GUI application that contains three functions as follows:
Add a record
Edit a record
Delete a record
A record contains two fields - Name and Profession
There are two restrictions for the application
You can't use database to store info. You have to use a flat file.
Total file should not be re-written for every add/delete operation.
So, my questions are mentioned below:
Q1. Which file format would be better? (.xml or .csv or .txt or any other)
Q2. How can we perform the add/delete operation without the whole file being re-written?
The second part of your question is answered here : Best Way to Write Bytes in the Middle of a File in Java
As for the format - I would go with something as simple as possible. You don't want to have to deal with a bunch of markup processing, as using RandomAccessFile, you will going directly to a byte position. A fixed width style format would be good, so that based on the record number, you can calculate the starting position of a record or field in the file, without having to read everything in the file. The fields would then be padded out to the fixed width with spaces or some other suitable character.
I would go with CSV, zipped. it is both readable, and editable externally.
If CSV is your choice, this can help: http://javacsv.sourceforge.net/
Did you look at this? http://sourceforge.net/projects/flatworm/
Also consider Apache Derbi and HSQLDB
Another solution is this http://www.coyotegulch.com/products/jisp/index.html
You can reinvent the wheel, but that is only required if this is an academic assigment...
Given that the whole file must not be rewritten, I would suggest using RandomAccessFile that allow you to read and write only the record you want.
For the file format, a binary file, using fixed length for the record : ex: Name on 20 characters, Profession on 30.
This will allow you to use the seek() method of RandomAccessFile to directly access your data.