<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Android sqllite csv to database</title>
	<atom:link href="https://assortmentofsites.com/android-sqllite-csv-to-database/feed/" rel="self" type="application/rss+xml" />
	<link>https://assortmentofsites.com/android-sqllite-csv-to-database/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=android-sqllite-csv-to-database</link>
	<description>Just another Assortmentofsites</description>
	<lastBuildDate>Wed, 16 Mar 2016 09:26:13 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.1</generator>
	<item>
		<title>By: admin</title>
		<link>https://assortmentofsites.com/android-sqllite-csv-to-database/#comment-2832</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Sat, 21 Nov 2015 06:01:05 +0000</pubDate>
		<guid isPermaLink="false">http://assortmentofsites.com/?p=785#comment-2832</guid>
		<description>FileStuff is a class in my code below is the code

&lt;code&gt;
/*
 * To change this template, choose Tools &#124; Templates
 * and open the template in the editor.
 */
package com.your.package;

import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.util.Base64;
import android.util.Log;
import android.widget.Toast;
import java.io.ByteArrayOutputStream;
import java.io.File;
import static java.io.File.separator;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.GZIPOutputStream;

/**
 *
 * @author
 * freelancer
 */
public class FileStuff {

    private static final String EXTERNAL_DIRECTORY = Environment.getExternalStorageDirectory().toString();//text
    public static final String DATA_DIRECTORY = EXTERNAL_DIRECTORY + separator + &quot;your dir&quot; + separator + &quot;Data&quot;;
    private static final String INNER_DELIMITER = &quot;,&quot;;//text
    private static final String QUOTES = &quot;\&quot;&quot;;//text
    private static final String LINE_END = &quot;\n&quot;;//text
    public String fileError, fileinfo, TAG = this.getClass().getSimpleName();
    ;
  
    /* Checks if external storage is available for read and write */

    private boolean isExternalStorageWritable() {
        String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state)) {
            return true;
        }
        return false;
    }

    /* Checks if external storage is available to at least read */
    public boolean isExternalStorageReadable() {
        String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state)
                &#124;&#124; Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
            return true;
        }
        return false;
    }

    /* Create data dir or return it */
    private File getDataDir(String tableCsv) throws IOException {
        // Get the directory for the app data directory.
        String f = tableCsv + &quot;.csv&quot;;
        File dataDirectory = new File(DATA_DIRECTORY, f);
        dataDirectory.delete();
        if (!dataDirectory.exists()) {
            File path = new File(DATA_DIRECTORY);//create directory
            path.mkdirs();
            if (!dataDirectory.createNewFile()) {
                Log.e(&quot;getStorageDir&quot;, &quot;file &quot; + f + &quot; not created&quot;);
                fileError = &quot;file &quot; + f + &quot; not created&quot;;
                fileinfo = &quot;unable to create backup file&quot;;
                return null;
            }
        }
        return dataDirectory;
    }

   

    public boolean createCsvSaveToFile(Cursor cursor, String fileName, Context c) throws IOException {
        String  ccsv = &quot;&quot;, csv = &quot;&quot;;
        int colunmCount = cursor.getColumnCount(), i;
        //check if extarnal drive is readerble
        if (!isExternalStorageWritable()) {
            fileError = &quot;Can not save to external storage&quot;;
            fileinfo = &quot;Please mount your SD card&quot;;
            return false;
        } else {
            //create CSV
            for (i = 0; i &lt; colunmCount; i++) {//GET COLUNM NAMES
                csv += QUOTES + cursor.getColumnName(i).toString() + QUOTES + INNER_DELIMITER;
            }
            csv = csv.replaceAll(&quot;,$&quot;, &quot;&quot;);
            
            csv += LINE_END;
            if (cursor.moveToFirst()) {
                do {
                    for (i = 0; i &lt; colunmCount; i++) {//GET COLUNM values
                        ccsv += QUOTES + cursor.getString(i) + QUOTES + INNER_DELIMITER;
                    }
                    ccsv = ccsv.replaceAll(&quot;,$&quot;, &quot;&quot;);
                    //encrypt
                    ccsv = encry(ccsv, keey);
                    csv += ccsv;
                    ccsv = &quot;&quot;;
                    csv += LINE_END;
                } while (cursor.moveToNext());
            }

            //save file
            File file = getDataDir(fileName);
            FileOutputStream out = new FileOutputStream(file);
            out.write(csv.getBytes());
            out.flush();
            out.close();
            if (!cursor.isClosed()) {
                cursor.close();
            }
            return true;
        }
    }
}

&lt;/code&gt;
</description>
		<content:encoded><![CDATA[<p>FileStuff is a class in my code below is the code</p>
<p><code><br />
/*<br />
 * To change this template, choose Tools | Templates<br />
 * and open the template in the editor.<br />
 */<br />
package com.your.package;</p>
<p>import android.content.Context;<br />
import android.content.SharedPreferences;<br />
import android.database.Cursor;<br />
import android.net.Uri;<br />
import android.os.Environment;<br />
import android.preference.PreferenceManager;<br />
import android.util.Base64;<br />
import android.util.Log;<br />
import android.widget.Toast;<br />
import java.io.ByteArrayOutputStream;<br />
import java.io.File;<br />
import static java.io.File.separator;<br />
import java.io.FileInputStream;<br />
import java.io.FileNotFoundException;<br />
import java.io.FileOutputStream;<br />
import java.io.IOException;<br />
import java.io.InputStream;<br />
import java.io.OutputStream;<br />
import java.net.URL;<br />
import java.nio.channels.FileChannel;<br />
import java.util.ArrayList;<br />
import java.util.logging.Level;<br />
import java.util.logging.Logger;<br />
import java.util.zip.GZIPOutputStream;</p>
<p>/**<br />
 *<br />
 * @author<br />
 * freelancer<br />
 */<br />
public class FileStuff {</p>
<p>    private static final String EXTERNAL_DIRECTORY = Environment.getExternalStorageDirectory().toString();//text<br />
    public static final String DATA_DIRECTORY = EXTERNAL_DIRECTORY + separator + "your dir" + separator + "Data";<br />
    private static final String INNER_DELIMITER = ",";//text<br />
    private static final String QUOTES = "\"";//text<br />
    private static final String LINE_END = "\n";//text<br />
    public String fileError, fileinfo, TAG = this.getClass().getSimpleName();<br />
    ;</p>
<p>    /* Checks if external storage is available for read and write */</p>
<p>    private boolean isExternalStorageWritable() {<br />
        String state = Environment.getExternalStorageState();<br />
        if (Environment.MEDIA_MOUNTED.equals(state)) {<br />
            return true;<br />
        }<br />
        return false;<br />
    }</p>
<p>    /* Checks if external storage is available to at least read */<br />
    public boolean isExternalStorageReadable() {<br />
        String state = Environment.getExternalStorageState();<br />
        if (Environment.MEDIA_MOUNTED.equals(state)<br />
                || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {<br />
            return true;<br />
        }<br />
        return false;<br />
    }</p>
<p>    /* Create data dir or return it */<br />
    private File getDataDir(String tableCsv) throws IOException {<br />
        // Get the directory for the app data directory.<br />
        String f = tableCsv + ".csv";<br />
        File dataDirectory = new File(DATA_DIRECTORY, f);<br />
        dataDirectory.delete();<br />
        if (!dataDirectory.exists()) {<br />
            File path = new File(DATA_DIRECTORY);//create directory<br />
            path.mkdirs();<br />
            if (!dataDirectory.createNewFile()) {<br />
                Log.e("getStorageDir", "file " + f + " not created");<br />
                fileError = "file " + f + " not created";<br />
                fileinfo = "unable to create backup file";<br />
                return null;<br />
            }<br />
        }<br />
        return dataDirectory;<br />
    }</p>
<p>    public boolean createCsvSaveToFile(Cursor cursor, String fileName, Context c) throws IOException {<br />
        String  ccsv = "", csv = "";<br />
        int colunmCount = cursor.getColumnCount(), i;<br />
        //check if extarnal drive is readerble<br />
        if (!isExternalStorageWritable()) {<br />
            fileError = "Can not save to external storage";<br />
            fileinfo = "Please mount your SD card";<br />
            return false;<br />
        } else {<br />
            //create CSV<br />
            for (i = 0; i < colunmCount; i++) {//GET COLUNM NAMES<br />
                csv += QUOTES + cursor.getColumnName(i).toString() + QUOTES + INNER_DELIMITER;<br />
            }<br />
            csv = csv.replaceAll(",$", "");</p>
<p>            csv += LINE_END;<br />
            if (cursor.moveToFirst()) {<br />
                do {<br />
                    for (i = 0; i < colunmCount; i++) {//GET COLUNM values<br />
                        ccsv += QUOTES + cursor.getString(i) + QUOTES + INNER_DELIMITER;<br />
                    }<br />
                    ccsv = ccsv.replaceAll(",$", "");<br />
                    //encrypt<br />
                    ccsv = encry(ccsv, keey);<br />
                    csv += ccsv;<br />
                    ccsv = "";<br />
                    csv += LINE_END;<br />
                } while (cursor.moveToNext());<br />
            }</p>
<p>            //save file<br />
            File file = getDataDir(fileName);<br />
            FileOutputStream out = new FileOutputStream(file);<br />
            out.write(csv.getBytes());<br />
            out.flush();<br />
            out.close();<br />
            if (!cursor.isClosed()) {<br />
                cursor.close();<br />
            }<br />
            return true;<br />
        }<br />
    }<br />
}</p>
<p></code><br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Me</title>
		<link>https://assortmentofsites.com/android-sqllite-csv-to-database/#comment-2831</link>
		<dc:creator>Me</dc:creator>
		<pubDate>Tue, 17 Nov 2015 13:57:17 +0000</pubDate>
		<guid isPermaLink="false">http://assortmentofsites.com/?p=785#comment-2831</guid>
		<description>FileStuff cannot be resolved into a type.. What do i need to do ?</description>
		<content:encoded><![CDATA[<p>FileStuff cannot be resolved into a type.. What do i need to do ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>https://assortmentofsites.com/android-sqllite-csv-to-database/#comment-2810</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Tue, 21 Jul 2015 10:02:59 +0000</pubDate>
		<guid isPermaLink="false">http://assortmentofsites.com/?p=785#comment-2810</guid>
		<description>the first row in the csv file, defines the table colunms</description>
		<content:encoded><![CDATA[<p>the first row in the csv file, defines the table colunms</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kanika</title>
		<link>https://assortmentofsites.com/android-sqllite-csv-to-database/#comment-2809</link>
		<dc:creator>kanika</dc:creator>
		<pubDate>Tue, 21 Jul 2015 07:06:52 +0000</pubDate>
		<guid isPermaLink="false">http://assortmentofsites.com/?p=785#comment-2809</guid>
		<description>how we will define the names of the different columns in the database table ?</description>
		<content:encoded><![CDATA[<p>how we will define the names of the different columns in the database table ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>https://assortmentofsites.com/android-sqllite-csv-to-database/#comment-2808</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Wed, 03 Jun 2015 13:00:49 +0000</pubDate>
		<guid isPermaLink="false">http://assortmentofsites.com/?p=785#comment-2808</guid>
		<description>you can change the logic to just get one file then call this function, readFromFile(csvfile); with the file.
just add a simple check before files.add(file); this will ensure only your file is added</description>
		<content:encoded><![CDATA[<p>you can change the logic to just get one file then call this function, readFromFile(csvfile); with the file.<br />
just add a simple check before files.add(file); this will ensure only your file is added</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jsjs</title>
		<link>https://assortmentofsites.com/android-sqllite-csv-to-database/#comment-2807</link>
		<dc:creator>jsjs</dc:creator>
		<pubDate>Sun, 31 May 2015 11:16:47 +0000</pubDate>
		<guid isPermaLink="false">http://assortmentofsites.com/?p=785#comment-2807</guid>
		<description>Is there a way just to select one  csv file, like not all of the csv on a directory</description>
		<content:encoded><![CDATA[<p>Is there a way just to select one  csv file, like not all of the csv on a directory</p>
]]></content:encoded>
	</item>
</channel>
</rss>
