3

I have a C structure with 2 attributes, say the content and the val How do I read this into an android file? Does android support any structure?

My structure is like

struct data[] = { {"aakash", 2260}, {"anuj", 1}} 

How to read such structures in android?

2

2 Answers 2

1

For Android supports Java Platform. Structure is not belong to Java. You Can Achieve the Same with Pojo Classes.

Public Class MyData { private String username; private double points; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public double getPoints() { return points; } public void setPoints(double points) { this.points = points; } public MyData(String username,double points) { this.username = username; this.points = points; } } MyData[] data = new MyData[2]; data[0]= new MyData("aakash", 2260); data[1]= new MyData("anuj", 1); 
Sign up to request clarification or add additional context in comments.

4 Comments

My database is very large..i cannot use classes for it...isn't it?
Here there are two Fields, so you can go ahead with Pojo classes, as I explained. How come Database is related in this context.
I have my data in a file, so how to I read the file... The file is in the from "aakash" 12 \n "anuj" 6 \n and so on
InputStream inputStream = getResources().openRawResource(R.raw.toc); // or you can use AssestManager to open File like this /* AssetManager am = context.getAssets(); InputStream is = am.open("test.txt"); */ System.out.println(inputStream); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); int i; try { i = inputStream.read(); while (i != -1) { byteArrayOutputStream.write(i); i = inputStream.read(); } inputStream.close(); } catch (IOException e) { e.printStackTrace(); }
0

If the structure is as simple as a String and an Integer, and you really wanna write to file using C, read using Java. You can use a Plain Text File, Use a CSV format to store the values. It'll be easy to read/write in both languages.

You can't store those objects into a binary file and have Java read it effortlessly. Although, If the file was created using Java, then it should be easy.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.