Home

Apps

Basics

Videos

Forum

Android Tutorial

Contact Us

Developers

Android application development

Google Android Developer

Hire Android App Developer

Rails developer

Android Applications

ADB

AnalogClock

Android apps

Android News

Android SDK

Android Tutorial

Android Videos

AutoCompleteTextView

Basic Application

Button

CheckBox

Common Issue

Datepicker

Dialog

Edittext

emulator

facebook

File Handling

Gallery

Google Map

image

Keyboard

Layout

Listview

media

MediaPlayer

Notification

Progress

RadioButton

RelativeLayout

screen

Scroll

Sliding Drawer

Spinner

Status Bar

TabBar

TableLayout

Textview

Time Picker

TitleBar

toast

ToggleButton

TTS

Tutorial

Twitter

Video

ViewFlipper

XML Parsing

See also..

World’s First Non-Touch Android Phone

YouTube 2.0 for Android updated with official Music Videos and Pre-Roll Ads

Google Goggles 1.3 for Android updated with Print Ads and Sudoku

Overview of Android Application Development

Opera unveils WAC-ready Widget Runtime for Android

Archives

January 2011

December 2010

November 2010

October 2010

September 2010

August 2010

July 2010

June 2010

May 2010

April 2010

March 2010

February 2010

January 2010

December 2009

November 2009

Widget Meta

Register

Log in

Entries RSS

Comments RSS

WordPress.org

Android Rss

World’s First Non-Touch Android Phone

YouTube 2.0 for Android updated with official Music Videos and Pre-Roll Ads

Google Goggles 1.3 for Android updated with Print Ads and Sudoku

Overview of Android Application Development

Opera unveils WAC-ready Widget Runtime for Android

Google Maps 5.0 for Android brings 3D and offline caching

Prey phone tracker app for Android is an open source anti-theft solution

YouTube 2.1 for Android brings in-page playback and improved UI

Happy New Year 2011

VLC Player for Android is arriving in a few weeks

Android how to create file in SD-Card-part 1.

July 12, 2010 in File Handling, Tutorial by S.Janardhanan

Hi Android Developers,

In this post we will discuss on the methods to create a file in SD card. In this series we will create a csv file and save it in SD card.

If you are trying the following snippet in Emulator then make sure you have created a AVD with SD card.

These are the steps to create AVD with SD card in eclipse.

Step 1:

Eclipse->Window->Android SDK and AVD manager->Virtual Devices.

Step 2:

Give the AVD name, Select your Target and give 1024 in the SD card size space.So that it create a SD card with 1 GB memory space.

Step 3:

To create a file make sure u have added the following Manifest permission

android.permission.WRITE_EXTERNAL_STORAGE

Step 4:

To use the created SD card we have to use the function Environment.getExternalStorageDirectory()

The csv file will be much important for android application developer in case of exporting the DB content and also creating report. We will do that in the next part.

Now we just create a simple CSV file. Use the following snippet to create a CSV file.

package com.csvtry;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;

public class csvtry extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

generateCsvFile("androidpeople.csv");

}
private static void generateCsvFile(String sFileName)
{
try
{
File root = Environment.getExternalStorageDirectory();
File gpxfile = new File(root, sFileName);
FileWriter writer = new FileWriter(gpxfile);

writer.append("SDK Name");
writer.append(',');
writer.append("SDK Number");
writer.append('\n');

writer.append("Eclairs");
writer.append(',');
writer.append("2.1");
writer.append('\n');

writer.append("Froyo");
writer.append(',');
writer.append("2.2");
writer.append('\n');

//generate whatever data you want

writer.flush();
writer.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}

download sourcecode here

Android how to create file in SD-Card-part 1.

Tags: android, card, create, csv, database, export, file, how to, sd
136210 Comments »http%3A%2F%2Fwww.androidpeople.com%2Fandroid-how-to-create-file-in-sd-card-part-1%2FAndroid+how+to+create+file+in+SD-Card-part+1.2010-07-12+09%3A45%3A33S.Janardhananhttp%3A%2F%2Fwww.androidpeople.com%2F%3Fp%3D1362

Android how to create file in SD-Card-part 1.

136210 Commentshttp%3A%2F%2Fwww.androidpeople.com%2Fandroid-how-to-create-file-in-sd-card-part-1%2FAndroid+how+to+create+file+in+SD-Card-part+1.2010-07-12+09%3A45%3A33S.Janardhananhttp%3A%2F%2Fwww.androidpeople.com%2F%3Fp%3D1362

John Mac said: On August 19, 2010

Very interesting info, i am waiting for more ! Keep updating your website and you will have a lot o readers.

Reply

Reddy said: On September 18, 2010

Thanks for your post.

If we want to read what the steps we have to follow.

Reply

SATYA.N said: On September 20, 2010

I tried this but the file is not created on the sdcard. do i need to get any permissions from android in manifest file??

Reply

dixen said: On September 21, 2010

i can't find csv file.where can i find that?

Reply

Nick said: On September 24, 2010

Yes, you do need permissions to write to the SD card. Here they are:

Nick

Reply

Nick said: On September 24, 2010

Darn thing ate my permissions tag, but the permissions you need are:

android.permission.WRITE_EXTERNAL_STORAGE

Nick

Reply

anemolius said: On October 5, 2010

Thanks for this clear and nice tutorial, this is right what I want. Looking forward to your new posts!

Reply

Prasad G Kulkarni said: On December 2, 2010

nice one,, thanx it helped me alot.. can you tell me where can i find the file androidpeople.csv

Reply

asadali said: On December 3, 2010

hello,

how can we find the size of Sd card and used as well as free space

i really appreciate if some one help me out

thanks

Reply

Ash said: On January 6, 2011

keep posting sir…..reming v r all waiting 4 ur posts.

but where can i find the file….i've tried to display the location using Log.d(……..) but no use. its displaying "/sdcard"..

Thanq

Reply

Leave a Reply

Click here to cancel reply.

Name *

Email *

Website

Comment

NoFollow Plugin created by Wordpress Plugin created by LunarPages Review and SimplyHosting Review. - 

Nightwish & Tech Addict!

Home

Contact

Nightwish Gallery

404 - Not Found

Sorry, no posts matched your criteria.

Categories

Announcements (6)

News (5)

Technology (3)

Uncategorized (51)

Recent Posts

Hostgator Black Friday Coupon 2010

Exchange Server 2010 Training DVD Review

Apple’s Back to the Mac Event

iPhone 4 – Worth The Costs?

New HTC WildFire Phone

Popular Posts

Get a Free Google Wave Invite!

How to Make your Computer Faster

Mobile Phone Lip-Reading Technology

This Blog is now DoFollow!

Samsung Galaxy Portal Review

How to get Indexed Quickly

Virgin Media to launch 200Mb/s Internet Connection

Lenovo IdeaPad S12 Review

How to set custom SMS Tones on iPhone

Upcoming Concerts

Recent Comments

Michael from CB Wealth Formula on How to get Indexed Quickly

Briyan on Mobile Phone Lip-Reading Technology

John on Mobile Phone Lip-Reading Technology

Mary on How to increase iPhone Battery Life

Rocko from alliance leveling guide on Mobile Phone Lip-Reading Technology

Advertisement

Links

iPhone Deals

ITC Electronics Store

Computer Memory

Teamspeak Server

Ventrilo Server

COD4 Servers

retail point of sale software

cheap netbooks and laptops

Server Memory

uk power adapters

Cheap Web Hosting

Product Information

WoW Cheats

WoW Hacks

Wordpress Themes

Job Search

What

job title, keywords or company name

Where

city (optional)

South Africa Jobs

Copyright © 2007 - Jake Ruston - is proudly powered by WordPress.

Notify me of followup comments via e-mail

Spam Protection by WP-SpamFree Plugin

To start connecting please log in first. You can also create an account.

Username

Password

Remember Me

Our Android Apps.

All in One Unit Converter
Android App

Refill Fuel Advance
Android App

World Clock
Android App

Cardoddler I
Android App

QR Generator
Android App

Your Ad Here

Pages

Apps

Basics

Forum

Android Tutorial

Videos

Contact Us

Adbrite

Your Ad Here

Search this site!…

Tags

android
android 2.2
Android App
Android application development
Android apps
Android developer
Android market
Android phones
application
background
bar
Button
code
color
custom
Dialog
Edittext
emulator
example
facebook
from
froyo
google
Google Android developer
hide
how to
image
Layout
Listview
phone
remove
screen
set
size
source
style
text
textsize
Textview
title
toast
Tutorial
Video
view
Window

Android Community – Business articles, blogs, videos, apps, reviews is proudly developed by Anubavam Wordpress Developers

Android Community - Business articles, blogs, videos, apps, reviews

Log In

Sign Up

Visit

Random Member

Random Group