-1
如何使用CsvWriter
以csv
格式編寫整數數組和字符串數組?CSVWriter對於整數數組
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Set;
import au.com.bytecode.opencsv.CSVReader;
import au.com.bytecode.opencsv.CSVWriter;
public class ArrayHash3
{
public static void main(String args[]) throws IOException
{
int[] WorkingDay = new int[13];
int i = 0;
String[] arrString = null;
int[] arrInt = null;
String[] Name = new String[13];
String file="C:\\Users\\Dhananjay Kumar\\Empdetail\\Detail.csv";
HashMap<String[],int[]> hashfunc=new HashMap<String[],int[]>();
CSVReader reader=new CSVReader(new FileReader(file));
String[] read;
while((read = reader.readNext()) !=null)
{
WorkingDay[i]=Integer.parseInt(read[2]);
Name[i]=read[0];
i++;
}
hashfunc.put(Name,WorkingDay);
hashfunc.get(Name);
Set<Entry<String[], int[]>> entrySet = hashfunc.entrySet();
for (Entry entry : entrySet)
{
arrInt = (int[]) entry.getValue();
arrString = (String[]) entry.getKey();
for(int j=0; j<arrInt.length; j++)
{
System.out.println(arrString[j]+":"+arrInt[j]);
}
}
String File1 = "C:\\Users\\Kumar\\Empdetail\\Detail6.csv";
CSVWriter fw = new CSVWriter(new FileWriter(File1, true));
fw.writeAll(arrString+","+arrInt);
fw.close();
}
}
沒有兄弟我有,因爲它我的需要...使用@ simas_ch – UserAtHome
然後請提供輸出應該什麼樣子 –
它應該像simas 26,dhananjay 56 ...它的意思是它應該包含名稱和值都... – UserAtHome