What is csv file in android

Android Read CSV File

This Android tutorial is to explain how to read and use a CSV file in an Android application. There is nothing fancy and is a simple tutorial for beginners.

This tutorial will answer two questions,

  1. Where should I put the CSV file in Android?
  2. How to read that CSV file from the app?

Where to put the CSV file in Android

Create a folder named “raw” inside the “res” folder and put the CSV file in it. Here I am not discussing about loading a CSV file from an external memory card. May be I will write about it separately. This is to hold simple text data in a CSV file and use it inside the application. Instead of a database for holding data we can use this as a substitute when the data is simple and lesser.

How to read CSV file

Nothing special since its Android. All we are going to use our standard Java code. Its better to use our own code instead of going to an API. Following class is an utility to read CSV file and it can be used from within the Android application.

So how to load the CSV file from “raw” folder and use the above utility to read it?

  • stats is the name of the CSV file to be read.
  • CSVFile is the above utility Java class (no external API used).

Example Android Application with CSV File

Now lets look at this example Android application where we have used a CSV file to load data. We have used the Android custom list view layout to load and display the data from CSV file. We have seen how to use the custom list view layout in Android in the linked tutorial and go through it to understand the detail.

MainActivity.java

ItemArrayAdapter.java

activity_mail.xml

item_layout.xml

Download the Example Android Application

Comments on «Android Read CSV File»

Useful Utility in Some Types of Application… Nice One Sir.

THANKS!
IF the word is gibberish?
How to solve?(utf-8)

List scoreList = csvFile.read();

for(String[] scoreData:scoreList ) <
itemArrayAdapter.add(scoreData);
>
over scoreData:scoreList it show me an error message .. “Type mismatch: cannot convert from element type Object to String[]”.. how to resolve it

The same problem:
“Type mismatch: cannot convert from element type Object to String[]”.

use List instead of List , in whole example.

I had to use List when declaring scoreList instead of just List in order to access an element of a row after using scoreList.get(Index) to get a row.

Great guide by the way. Very helpful

Читайте также:  Iphone как перенести данные с андроид

use List “” (Without quotes) instead of List and this works great

Comments are closed for «Android Read CSV File».

Источник

Full Guide to Import CSV Contacts to Android Phone in 2021

As a common file format, CSV is widely supported by consumer, business, and other applications. For example, many of you Android users have your phone contacts saved in CSV file format. What if you change to a new Android phone like Samsung Galaxy S20/S10/S10+/S10e? Or your contacts in your Android are deleted by accident? You must need to import contacts from a CSV file stored somewhere else, for example, in your computer, to your Android. So how to easily import CSV contacts to Android? In this article, you will find ideal solutions.

Why Do You Need to Transfer Contacts in CSV Format to Android?

People have different reasons to transfer CSV contacts from computer to Android mobile phones. I have vaguely mentioned above, but it is necessary to sum up again. The common reasons are as below:

In order to prevent from losing data, people are supposed to back them up on the computer. Since CSV is a common contacts backup file on computer, if you accidentally delete or lose them on your Android phone, it is possible for you to import CSV contacts from PC to Android phone.

If you want to switch to a new Android phone, you need to import the contacts to your new device from the old one. Nobody wants to move data manually, especially when there is a large amount of it. Thus, importing the backed up CSV contacts file from the computer to Android should be the best choice.

Here I provide three easy methods for you if you want to import CSV contacts to Android.

Part 1: Import Contacts to Android with Gmail Account

If you have a Gmail Account and don’t want to download any other software, this method may be suitable for you. Just follow the steps below to learn how to import contacts to Android with Gmail Account.

Step 1: Sign into your Gmail account

Open the browser on your computer, sign into your Google account and browse to the left panel and click «Gmail«. Choose «Contacts» in the drop-down menu.

Step 2: Click «More» and choose «Import»

After you enter the «Contacts» tab, find «More» and click «Import» in the drop-down menu.

Step 3: Choose CSV file and import it to your Gmail account

Now click «Choose Files» on the popup window to find the CSV file you have stored and import it to your Gmail account.

Step 4: Import CSV contacts to your Android from Gmail account

Now the CSV file has been imported to your Gmail account, and you can sign into it on your Android. Then go to Settings, find «Accounts & sync» option on your Android phone and choose your Google account. After that, click «Sync Contacts» > «Sync now«, and then all CSV contacts will be imported to your Android.

So this is the way to import contacts to Android phone from CSV file with Google account.

Читайте также:  Автоматическая блокировка экрана для андроид

Part 2: Import Contacts to Android Phone from CSV Directly

It doesn’t matter if you don’t have a Gmail account. Now I will teach you another way to import contacts to Android phone from CSV directly. But first you need an Excel CSV file on your computer. If you have no such a file, follow the Step 1 to create one. If you already have, then skip step 1 and start from step 2.

Step 1: Create an Excel CSV file on your computer

Create a new Excel document and fill the cells with your contacts’ information in the following way. When finished, save it as CSV format.

Step 2: Convert the Excel CSV file to vCard file

— Log into your Google account in a browser.
— Choose «Contacts» on the left side. Click «More» > «Import«, then click «Select file» to choose the CSV file.
— Next, click the «Import» button on the popup window.
— Now the Excel CSV has been transferred to your Google account. You can view it on your Android phone.
— Next, browse to the left side again and click the «Export» button to export the Excel CSV file to vCard file, which is compatible on your Android.

Step 3: Uploading vCard file to Google Drive

Enter the Google Drive in the browser and log into your Google account. Browse to the left column, click «+New» and choose «File upload«. Then choose the vCard file you have exported in Step 2.

Step 4: Download vCard file to your Android

Download and launch Google Drive app on your Android and log into your Google account. Find the vCard file you have uploaded, press it and choose «Download«. Then it will be downloaded to your Android.

Step 5: Import contacts to your Android

Run the Contacts app on your Android. Click the three-dot icon on the right upper corner of the screen. Select «Settings» or «Manage contacts«. Then click «Import/Export Contacts » button and choose «Import» > «Internal storage» > «Phone» to choose the vCard file. Then the contacts will be imported to your Android.

Note: Step 5 might be a little different if operated in Android phones with different phone models.

Above are the concrete steps to import contacts to Android from CSV directly.

Part 3: Comparison among the Above 2 Methods of Importing CSV Contacts to Android

Apparently transferring CSV contacts to Android with Gmail account is much more convenient than the second method. With so many steps, importing contacts to Android from CSV directly is more time-consuming. You have to download apps and you have to import and export the file for many times. It is a little troublesome. If you have a Gmail account, you’d better not try this method.

Importing CSV contacts to Android with Gmail account is a good and very convenient method. It has no difficulties in solving your problem if you only want to import CSV contacts to your Android. However if you want to do some other operations like editing your contacts data, it doesn’t work. In this case, you may need another tool to make it.

Читайте также:  Delta touch doom android

Tips: How to export contacts from Android to CSV? Or how to manage Android contacts?

If you want to export Android contacts to CSV file or manage contacts on Android devive more freely, the Coolmuster Android Assistant is available and reliable for you.

On the one hand, besides the CSV format, this Android contact manager can enable you to convert the Android contacts to other contact formats as required, such as HTML, TEXT, VCF, BAK, XML and outlook.

On the other hand, it also allows you to edit, delete and add Android contacts on the computer. No matter you want to import contacts to Android or export Android contacts to the computer, it can meet your demands. Besides contacts, it extensively supports other categories of files transfer which includes SMS, call logs, music, videos, photos, etc. These fantastic features are unique and unrivaled.

So these are all the methods I want to share with you. If you are troubled by the problem of importing CSV contacts to your Android, you can follow these steps and they will help you a lot.

Источник

Android — How to Parse CSV file in Android with sample code for example?

To download the code, login with one of the following social providers.

Login Login

Be patient. we are fetching your source code.

Objective

You will get Final Output:

We are using Category.csv file in this example — you can follow the steps given below.

Screenshot of CSV file:

Step 1 Add .jar files

First we need to add following Jar file

You can download this jar file from the following link:

Step 2 CSVReader Class

Assume that Our CSV file contains two fields:

Fields Datatype
categoryId Integer
categoryName String

We can fetch these fields data using the following code:

Now If we want to fetch categoryId and categoryName fields than we can use the list as following:

i.e:

list.get(1)[0] This will return categoryId of Integer from first row of csv file.
list.get(1)[1] This will return categoryName of String from first row of csv file.

list.get(index): This will return array that contains data of particular row of csv file.

I hope you found this blog helpful Parse CSV file in Android. Let me know if you have any questions or concerns regarding Parsing CSV file in Android, please put a comment here and we will get back to you ASAP.

Got an Idea of Android App Development? What are you still waiting for? Contact us now and see the Idea live soon. Our company has been named as one of the best Android App Development Company in India.

Tejas Jasani

An entrepreneur who has founded 2 flourishing software firms in 7 years, Tejas is keen to understand everything about gaming — from the business dynamics to awesome designs to gamer psychology. As the founder-CEO of a company that has released some very successful games, he knows a thing or two about gaming. He shares his knowledge through blogs and talks that he gets invited to.

Источник

Оцените статью