java中读取csv文件,并在文件末尾添加数据

/**
	 * 读取一行数据然后按照标点或者双引号,读取出属性值
	 * 
	 * @throws IOException
	 */
	public static void writeCSV(int id, CdataModel cdata, String logFile)
			throws IOException {
		File file = new File(logFile); 
		FileOutputStream out = new FileOutputStream(file, true);
		OutputStreamWriter osw = new OutputStreamWriter(out, "GB2312");
		BufferedWriter bw = new BufferedWriter(osw);
		if (id == 1) {
			bw.write("id" + "," + "cnd" + "," + "terminalId" + "," + "date"
					+ "," + "x" + "," + "y" + "," + "gridX" + "," + "gridY"
					+ "," + "speed" + "," + "dir" + "," + "stat" + ","
					+ "event" + "," + "high" + "\r\n");//
			bw.write(id + "," + "$" + cdata.getFcd() + ","
					+ cdata.getTerminalId() + "," + cdata.getTime() + ","
					+ cdata.getX() + "," + cdata.getY() + ","
					+ cdata.getGridX() + "," + cdata.getGridY() + ","
					+ cdata.getSpeed() + "," + cdata.getDir() + ","
					+ cdata.getStat() + "," + cdata.getEvent() + ","
					+ cdata.getHigh() + "#" + "\r\n");
		} else {
			bw.write(id + "," + "$" + cdata.getFcd() + ","
					+ cdata.getTerminalId() + "," + cdata.getTime() + ","
					+ cdata.getX() + "," + cdata.getY() + ","
					+ cdata.getGridX() + "," + cdata.getGridY() + ","
					+ cdata.getSpeed() + "," + cdata.getDir() + ","
					+ cdata.getStat() + "," + cdata.getEvent() + ","
					+ cdata.getHigh() + "#" + "\r\n");
		}
		bw.close();
		osw.close();
		out.close();
	}

你可能感兴趣的:(java)