有人可以帮助我如何在特定行的末尾插入新值吗?我想为每个标记保存或错误的状态插入一个值。当我从对话框中单击特定按钮时,应插入以下值:已保存或不正确。
这是我的CSV:
1,45.66680458,25.60458787
2,45.66672655,25.6047773
3,45.66670734,25.60465392
当我写的时候应该怎样:
1,45.66680458,25.60458787,salvat
2,45.66672655,25.6047773,salvat
3,45.66670734,25.60465392,gresit
状态为“保存”和“不正确”的更新的工作代码:
bt_nu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
marker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
dialog.dismiss();
String salvat = "salvat";
BufferedReader br=null;
BufferedWriter bw=null;
final String lineSep=System.getProperty("line.separator");
try {
File file = new File(getExternalFilesDir(null), "fisier.csv");
File file2 = new File(getExternalFilesDir(null), "fisier1.csv");//so the
br = new BufferedReader(new InputStreamReader(new FileInputStream(file))) ;
bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file2)));
String line = null;
for ( line = br.readLine(); line != null; line = br.readLine())
{
String[] RowData = line.split(",");
Double latitudine = Double.valueOf(RowData[1]);
Double longitudine = Double.valueOf(RowData[2]);
if (latitudine == coords.latitude && longitudine == coords.longitude ) {
String addedColumn = String.valueOf(salvat);
bw.write(line + "," + addedColumn +lineSep);
}
else {
bw.write(line + lineSep);
}
file2.renameTo(file);
}
}catch(Exception e){
System.out.println(e);
}finally {
if(br!=null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(bw!=null) {
try {
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
);
bt_gresit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
marker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
dialog.dismiss();
String gresit = "gresit";
BufferedReader br=null;
BufferedWriter bw=null;
final String lineSep=System.getProperty("line.separator");
try {
File file = new File(getExternalFilesDir(null), "fisier.csv");
File file2 = new File(getExternalFilesDir(null), "fisier1.csv");//so the
br = new BufferedReader(new InputStreamReader(new FileInputStream(file))) ;
bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file2)));
String line = null;
for ( line = br.readLine(); line != null; line = br.readLine())
{
String[] RowData = line.split(",");
Double latitudine = Double.valueOf(RowData[1]);
Double longitudine = Double.valueOf(RowData[2]);
if (latitudine == coords.latitude && longitudine == coords.longitude ) {
String addedColumn = String.valueOf(gresit);
bw.write(line + "," + addedColumn+lineSep);
}
else {
bw.write(line + lineSep);
}
file2.renameTo(file);
}
}catch(Exception e){
System.out.println(e);
}finally {
if(br!=null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(bw!=null) {
try {
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}