//Taran Stuckman - Mushroom Data Converter import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.Vector; public class Main { //Read data from file into vector private static Vector> readIn(String fname) throws IOException{ FileInputStream fis = new FileInputStream(fname); BufferedReader br = new BufferedReader(new InputStreamReader(fis)); Vector> attributes = new Vector>(); String line = null; while ((line = br.readLine()) != null) { String[] splitLine = line.split(","); Vector v = new Vector(Arrays.asList(splitLine)); attributes.add(v); } br.close(); return attributes; } //adds column numbers to the values private static Vector> labelColumns(Vector> attributes){ Vector> labeledAttributes = new Vector>(); for(int i = 0; i < attributes.size(); i++){ Vector row = new Vector(); for(int j = 0; j < attributes.get(0).size(); j++){ row.add(Integer.toString(j)+attributes.get(i).get(j)); } labeledAttributes.add(row); } return labeledAttributes; } //prints new vector to the output file private static void printV(Vector> v,String fname) throws FileNotFoundException{ PrintWriter pw = new PrintWriter(fname); for(int i = 0; i < v.size(); i++){ for(int j = 0; j < v.get(0).size(); j++){ if(j == v.get(0).size() -1){ pw.print(v.get(i).get(j)+"\n"); }else{ pw.print(v.get(i).get(j)+","); } } } pw.close(); } //main driver public static void main(String[] args){ try { String in = args[0]; String out = args[1]; Vector> attributes = readIn(in); Vector> labeledAttributes = labelColumns(attributes); printV(labeledAttributes,out); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }