I'm just starting to learn some Java from a .NET, C#, and C++ background. Anyways the code presented to me is below, with a few basic questions following:
package com.SCM.FRS; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.Writer; import java.util.ArrayDeque; import java.util.Collection; import java.util.Deque; import java.util.HashMap; import java.util.Iterator; import java.util.Vector; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class FileComparison { /** * * @param f file to read in * @return rows in the file * @throws IOException */ private static Deque<String[]> getCollumns(String f) throws IOException{ FileInputStream fstream = new FileInputStream(f); DataInputStream input = new DataInputStream(fstream); BufferedReader in = new BufferedReader(new InputStreamReader(input)); //Header String line = in.readLine(); //Header 2 then collumns Deque<String[]> values = new ArrayDeque<String[]>(); while (in.ready()){ line = in.readLine(); String[] types = line.split("\\|"); values.add(types); } return values; } /** * * @param args [0] is the new file [1] is original * @throws IOException */ public static void main (String args[]) throws IOException{ if (args.length != 2){ System.out.println(args.length); System.out.println("This program must have two inputs"); System.out.println("First is the new file, second the original"); System.exit(0); } Deque<String[]> newFile = getCollumns(args[0]); Deque<String[]> oldFile = getCollumns(args[1]); //I am assuming header is the same for both of them String[] headers = newFile.pop(); oldFile.pop(); HashMap <String, Integer> hash = new HashMap <String, Integer>(); HashMap <String, String> examples = new HashMap <String, String>(); //HashMap <String, File> files = new HashMap <String, File>(); String fileBase = args[0].substring(0,args[0].lastIndexOf(".")); File report = new File(fileBase + "_report_summary.txt"); report.createNewFile(); HashMap <String, Vector<String>> buffs = new HashMap <String, Vector<String>>(); for (int i = 0; !newFile.isEmpty(); i++){ String[] newInput = newFile.pop(); String[] oldInput = oldFile.pop(); for (int j = 0; j < newInput.length && j < oldInput.length; j++){ if (!newInput[j].matches(oldInput[j])){ String message = "On row " + i + " was: " + oldInput[j] + " is now " + newInput[j] + "\r\n"; if (hash.containsKey(headers[j])){ hash.put(headers[j], hash.remove(headers[j]) + 1); /*File f = files.get(headers[j]); Writer output = new BufferedWriter(new FileWriter(f, true)); output.append(message); output.close();*/ Vector <String> vec = buffs.get(headers[j]); vec.add(new String(message)); }else{ Vector <String> vec = new Vector<String>(); vec.add(new String(message)); buffs.put(headers[j], vec); hash.put(headers[j], 1); examples.put(headers[j], message); /* File f = new File (fileBase + "_" + headers[j] + ".txt"); f.createNewFile(); Writer output = new BufferedWriter(new FileWriter(f)); files.put(headers[j], f); output.write(message); output.close();*/ } } } } Collection<String> examplesDump = examples.values(); Collection<String> examplesKeys = examples.keySet(); Iterator<String> itter = examplesDump.iterator(); Iterator<String> itterKeys = examplesKeys.iterator(); while(itter.hasNext()){ Writer output = new BufferedWriter(new FileWriter(report, true)); String key = itterKeys.next(); output.write(key + "has been changed " + hash.get(key) + "times\r\n"); output.write(itter.next() + "\r\n"); output.close(); } Collection<Vector<String>> buf = buffs.values(); Collection<String> bufKeys = buffs.keySet(); Iterator <Vector<String>> itt = buf.iterator(); itterKeys = bufKeys.iterator(); ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(fileBase + "_report.zip")); while(itt.hasNext()){ /*File f = new File (fileBase + "_" + itterKeys.next() + ".txt"); f.createNewFile(); Writer output = new BufferedWriter(new FileWriter(f));*/ String name = new File(args[0]).getName(); name = name.substring(0,name.lastIndexOf(".")); zip.putNextEntry(new ZipEntry(name + "_" + itterKeys.next() + ".txt")); Vector <String> messages = itt.next(); for (int i = 0; i < messages.size();i++){ zip.write(messages.elementAt(i).getBytes()); } zip.closeEntry(); } zip.close(); } }
- In the line that says "private static Deque<String[]> getCollumns(String f) throws IOException{" what is the getCollumns(string f) ... part mean? So far I've only understood that you have private static and then function name
- The comment says f is the file to read in, however where do you set this variable to point to the file you want the program to read?