问题描述
我的工作在Android项目中,我要创建从一些数据的CSV文件。我能够通过创建字幕创建CSV文件和存储数据。
I am working on an ANDROID project where i have to create a CSV file from some data.I am able to create csv file and store data by creating Captions.
code一小段,下面给出::
Code Snippet for that is given Below::
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 {
public static String abc=null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
generateCsvFile("Example1.csv");
}
private static void generateCsvFile(String sFileName)
{
try
{
File root = Environment.getExternalStorageDirectory();
File gpxfile = new File(root, sFileName);
FileWriter writer = new FileWriter(gpxfile);
abc="Guwahati";
writer.append("Emp_Name");
writer.append(',');
writer.append("Adress");
writer.append('\n');
writer.append("hussain");
writer.append(',');
writer.append("Delhi");
writer.append('\n');
//generate whatever data you want
writer.flush();
writer.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
正如上文code,我们可以看到,Example1.csv创建并存储在SD卡。我的作品精美绝伦......
As in above code, we can see, Example1.csv is created and stored in SDCARD.I works absolutely fine....
不过,我想写在新的行和列的一些新的数据Example1.csv。
But i want to write some new data in new rows and columns in Example1.csv.
但是,当我尝试了一些新的数据再次运行模拟器,它取代现有的行数据。
But when i try to run emulator again with some new data, it replaces existing row data.
我的问题是,我们怎么能写在新行的新数据,而无需更换previous数据?如何写在新行新的数据???
My question is that, how can we write new data in new row without replacing previous data?How to write new data in new rows ???
我停留在这...请大家给我点建议如何着手。
I am stuck on this...Please give me suggestions how to proceed ..
在此先感谢....
推荐答案
您可以尝试使用
FileWriter(String filename, boolean append)
将数据追加到该文件的末尾
to append data to the end of the file
这篇关于如何在现有的CSV文件中Android商店新的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!