CSV to CSV comparison utility - java

I am working on a project where I need to compare 2 CSVs for equality. Its just a single row in each CSV with multiple columns and report the differences in form of columna name and value which are different. For eg :
CSV 1 :
Name Roll No Dept
Brij 1 IT
CSV 2 :
Name Roll No Dept
Brij 2 IT
I need to report the diff as
Roll No 1 does not match Roll No 2 i.e. Col name and value in both csvs
My work till now :
#Test
public void f() {
try {
FileReader reader1 = new FileReader(
new File(System.getProperty("user.dir") + "\\src\\test\\resources\\csvFile\\Reader.csv"));
FileReader reader2 = new FileReader(
new File(System.getProperty("user.dir") + "\\src\\test\\resources\\csvFile\\Reader - Copy.csv"));
CSVReader csvReader1 = new CSVReader(reader1);
CSVReader csvReader2 = new CSVReader(reader2);
String[] nextRecordReader1;
String[] nextRecordReader2;
// we are going to read data line by line
while ((nextRecordReader1 = csvReader1.readNext()) != null
&& (nextRecordReader2 = csvReader2.readNext()) != null) {
checkEquality(nextRecordReader1, nextRecordReader2);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void checkEquality(String[] s1, String[] s2) {
if (s1 == s2) {}
if (s1 == null || s2 == null) {}
int n = s1.length;
if (n != s2.length) {}
for (int i = 0; i < n; i++) {
if (!s1[i].trim().equals(s2[i].trim())) {
System.out.println(s1[i] + " is not equal to " + s2[i]);
}
}
}
This gives me the below result :
1 is not equal to 2
I am not able to mention the column name. How shall I do that ?

public void checkEquality(String[] s1, String[] s2) {
if (s1 == s2) {}
if (s1 == null || s2 == null) {}
String[] headers= new String[]{"Name","Roll No","Dept"};
int n = s1.length;
if (n != s2.length) {}
for (int i = 0; i < n; i++) {
if (!s1[i].trim().equals(s2[i].trim())) {
System.out.println(headers[i]+" "+s1[i] + " is not equal to " headers[i]+" "+ s2[i]);
}
}
}
You need a collection to hold column headers, and use this collection to get header based on index.

enter code here
public class SampleTest {
int rowCountCounter;
String[] headers1;
String[] headers2;
#Test
public void f() {
try {
FileReader reader1 = new FileReader(
new File(System.getProperty("user.dir") + "\\src\\test\\resources\\csvFile\\Reader.csv"));
FileReader reader2 = new FileReader(
new File(System.getProperty("user.dir") + "\\src\\test\\resources\\csvFile\\Reader - Copy.csv"));
CSVReader csvReader1 = new CSVReader(reader1);
CSVReader csvReader2 = new CSVReader(reader2);
String[] nextRecordReader1;
String[] nextRecordReader2;
rowCountCounter=0;
// we are going to read data line by line
while ((nextRecordReader1 = csvReader1.readNext()) != null
&& (nextRecordReader2 = csvReader2.readNext()) != null) {
if(rowCountCounter==0) {
headers1=nextRecordReader1;
headers2=nextRecordReader2;
}
checkEquality(nextRecordReader1, nextRecordReader2);
rowCountCounter++;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void checkEquality(String[] s1, String[] s2) {
if (s1 == s2) {}
if (s1 == null || s2 == null) {}
int n = s1.length;
if (n != s2.length) {
System.out.println("Header in CSV1 " + n + " is not equal to header in CSV2 " + s2.length);
}
boolean headerFlag=true;
for (int i = 0; i < n; i++) {
if(rowCountCounter==0) {
if (!s1[i].trim().equals(s2[i].trim())) {
System.out.println("CSV1 header "+s1[i] + " is not equal to CSV2 header " + s2[i]);
headerFlag=false;
}
}else {
if (!s1[i].trim().equals(s2[i].trim())) {
System.out.println("CSV1 "+headers1[i] +" cellvalue "+" \"" +s1[i] +"\"" +" is not equal to CSV2 " + headers2[i]+" value \""+s2[i]+"\"");
headerFlag=false;
}
// else {
// System.out.println("CSV data is equal");
// }
}
}
if(headerFlag==true && rowCountCounter==0) {
System.out.println("CSV headers are equal.Below are the headers");
for(int k=0;k<s1.length;k++) {
System.out.print(s1[k]+" ");
}
}
if(headerFlag==true && rowCountCounter!=0) {
System.out.println("CSV data is equal.");
}
}
}

Related

Apache POI Mixed word format not working properly

FileInputStream fileInputStream = new FileInputStream(filePath);
XWPFDocument document = new XWPFDocument(fileInputStream);
for (XWPFParagraph p : document.getParagraphs()) {
Boolean isPrg=true;
XmlCursor cursor = p.getCTP().newCursor();
cursor.selectPath(
"declare namespace w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' .//*/w:txbxContent/w:p/w:r");
List<XmlObject> ctrsintxtbx = new ArrayList<XmlObject>();
while (cursor.hasNextSelection()) {
cursor.toNextSelection();
XmlObject obj = cursor.getObject();
ctrsintxtbx.add(obj);
}
for (XmlObject obj : ctrsintxtbx) {
CTR ctr = CTR.Factory.parse(obj.newInputStream());
XWPFRun bufferrun = new XWPFRun(ctr, (IRunBody) p);
String text = bufferrun.getText(0);
if (text != null && text != "") {
isPrg= false;
text = text.replace("[RECEPIENT_NAME]", name).replace("[ADDRESS1]", address1).replace("LETTER_GEN_DT", date)
.replace("[ID]",sbsbid).replace("MEMR_RX_ID", memrid)
.replace("MEMR_MCTR_RX_GROUP", memrgroup).replace("MEMR_MCTR_RXBIN", memrrxbin)
.replace("MEMR_MCTR_PCN", memrpcn);
System.out.println("header line is "+ text);
if((address2 == null || address2.equals("")) && (address3 == null || address3.equals(""))) {
text = text.replace("[ADDRESS2]",city+", "+state+" "+zip).replace("[ADDRESS3]","").replace("[ZIP]", "").replace("[CITY]", "").replace("[STATE]", "");
}
else if((address2 != null && !address2.equals("")) && (address3 == null || address3.equals(""))) {
text = text.replace("[ADDRESS2]",address2).replace("[ADDRESS3]",city+", "+state+" "+zip).replace("[ZIP]", "").replace("[CITY]", "").replace("[STATE]", "");
}
else if((address2 == null || address2.equals("")) && (address3 != null && !address3.equals(""))) {
text = text.replace("[ADDRESS2]",address3).replace("[ADDRESS3]",city+", "+state+" "+zip).replace("[ZIP]", "").replace("[CITY]", "").replace("[STATE]", "");
}
else if((address2 != null && !address2.equals("")) && (address3 != null && !address3.equals(""))) {
text = text.replace("[ADDRESS2]",address2).replace("[ADDRESS3]",address3).replace("[ZIP]",zip).replace("[CITY]", city).replace("[STATE]", state);
}
bufferrun.setText(text,0);
}
obj.set(bufferrun.getCTR());
}
if(isPrg) {
String runTxt="";
p.getCTP().documentProperties();
for(int i = 0; i < p.getRuns().size(); i++)
{
runTxt=runTxt+ p.getRuns().get(i);
}
System.out.println("main footer is :"+runTxt);
runTxt=runTxt.replace("[RECEPIENT_NAME]", name).replace("[PDP_NAME]", pdpname)
.replace("[ENRL_EFF_DT]", enrolldate).replace("[GLBL_PHONE_NUMBER]", phoneNumber);
int psize= p.getRuns().size();
if(psize>1) {
for(int i = 0; i < psize-1; i++)
{
try
{
p.removeRun(psize - i - 1);
}
catch(Exception e)
{
//e.printStackTrace();
}
}
}
for(XWPFRun ffr:p.getRuns()) {
ffr.setText(runTxt,0);
break;
}
}
}
outFilePath = filePath.replace(".docx", "_convert.docx");
FileOutputStream out = new FileOutputStream(
new File(outFilePath));
document.write(out);
out.close();
System.out.println("Output.docx written successully");
} catch (IOException | SQLException e) {
System.out.println("We had an error while reading the Word Doc");
}
return outFilePath;
}
Input Text :
will automatically terminate without notice when the base Contract terminates for any reason
Output i am getting like this:
will automatically terminate without notice when the base Contract terminates for any reason
For output also i need Bold text format after replacing the words in documents
Expected Output is :
will automatically terminate without notice when the base Contract terminates for any reason

How to fix input getting cut off by output

So, I'm trying to create a function (If not pretty) IRC client using no libraries, written in Java. I've gotten almost everything working, the only problem is that I'm currently getting user input using System.in. And if someone else in the channel sends a message while I'm in the middle of typing, it cuts off what I currently have, and I need to guess where I am in the string. I want to know if there's a way to separate user input from the output of the program, so that this doesn't happen. This is the code in question:
new Thread(() -> {
while(connected[0]) {
String output = sc.nextLine();
if(!output.startsWith("~") && !output.startsWith("/")) {
try {
writeToSocket("PRIVMSG " + focused[0] + " " + output);
} catch (IOException e) {
e.printStackTrace();
}
}
if(output.substring(1).toLowerCase().startsWith("quit")) {
String[] split = output.substring(5).split(" ");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < split.length; i++) {
if(i == 0) {
sb.append(split[i]);
}
sb.append(" ").append(split[i]);
}
try {
writeToSocket("QUIT " + sb.toString());
connected[0] = false;
} catch (IOException e) {
e.printStackTrace();
}
}else if(output.substring(1).toLowerCase().startsWith("focus")) {
String get = output.substring(7);
if(!channels.contains(get)) {
print("Not connected to channel");
}else {
try {
writeToSocket("PART " + focused[0]);
writeToSocket("JOIN " + get);
} catch (IOException e) {
e.printStackTrace();
}
focused[0] = get;
}
}else if(output.substring(1).toLowerCase().startsWith("join")) {
String get = output.substring(6);
channels.add(get);
}
if(output.startsWith("/") && output.substring(1).toLowerCase().startsWith("msg")) {
String[] split = output.substring(5).split(" ");
String username = split[0];
StringBuilder msg = new StringBuilder();
for(int i = 1; i < split.length; i++) {
if(i == 1) {
msg.append(split[i]);
continue;
}
msg.append(" ").append(split[i]);
}
try {
writeToSocket("PRIVMSG " + username + " " + msg.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
}
}).start();

Android insert data in Db from file which have multiple lines for each Insert query

I want to pre-populate my database. So I generate SQL queries from browser and write code to insert them in db. It is working fine for the single line query but most insert queries have multiple line for example `
INSERT INTO `poem` VALUES (780,'سلام القلب واشواقه
من قلب يحب مجنونه
ياليت هالقلب يحن
ويقول هالدنيا
ماتسوى دون *_*','0',NULL);`
My requirement is to insert them as they are. That is the method i wrote for multiple line (works perfect for single line query)
public static int countLines(InputStream is) throws IOException {
try {
byte[] c = new byte[1024];
int count = 0;
int readChars = 0;
boolean empty = true;
int index = 0;
while ((readChars = is.read(c)) != -1) {
empty = false;
String temp = new String(c);
for (int i = 0; i < readChars; i++) {
if (c[i] == ';' && index == 0) {
index++;
} else if (c[i] == '\n' && index == 1) {
index++;
} else if (c[i] == '\t' && index == 2) {
index++;
} else if (c[i] == 'I' && index == 3) {
count++;
index = 0;
} else {
i -= index;
index = 0;
}
}
}
return (count == 0 && !empty) ? 1 : count + 1;
} finally {
is.close();
}
}
Anyone have idea how to insert such queries from file to DB.?
Any help would be great. Thanks
What you are asking is an ugly way of doing things. Use sqliteassethelper to create prepopulated databases and tables. It works extremely similar to SQLiteOpenHelper so it is very easy to use.
Sorry for late response in case of anyone having same issue
Here is the solution step by step
I create a .sql file which contain insert queries (some Include multiline queries) ends with :.
In my onCreate() method of SQLiteOpenHelper I m counting lines of my file using getFileLineCount(). This method return me the count of line. This line count is never used , but I had it because if all your queries are single line, it might comes into play. You can skip this method.
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE \"" + TABLE_POEM + "\" (\"" + POEM_LOCAL_ID + "\" INTEGER PRIMARY KEY AUTOINCREMENT , \"" + POEM_TEXT + "\" TEXT,\"" + POEM_ID + "\" INTEGER , \"" + POEM_IS_FAV + "\" TEXT);");
int totalLineCount = getFileLineCount("poem.sql");
int insertCount = insertFromFile(db, "poem.sql", totalLineCount);
Log.d("DatabaseHelper", "------------onCreate(SQLiteDatabase db) >>>>>>> completed--------");
}
private int getFileLineCount(String assetFilePath) {
InputStream insertStream = null;
int totalCount = 0;
try {
insertStream = context.getAssets().open(assetFilePath);
totalCount = FileUtil.countLines(new BufferedInputStream(insertStream));
} catch (Exception e) {
e.printStackTrace();
} finally {
if (insertStream != null) {
try {
insertStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return totalCount;
}
By using this method I insert queries from file. It handles both single line queries and multi line queries. First I check if line contain ";" it means the line is ended else not ended. Pretty simple it was at the end.
while ((currentLine = insertReader.readLine()) != null) {
if (currentLine.length() != 0) {
if (currentLine.charAt(currentLine.length() - 1) == ';') {
insertInDb(db, insertStr + "\n" + currentLine);
insertStr = "";
} else {
insertStr += currentLine;
}
}
}
private int insertFromFile(SQLiteDatabase db, String assetFilePath, int totalCount) {
int result = 0;
BufferedReader insertReader = null;
try {
InputStream insertStream = context.getAssets().open(assetFilePath);
insertReader = new BufferedReader(new InputStreamReader(insertStream));
db.beginTransaction();
while (insertReader.ready()) {
// String insertStr = insertReader.toString();
String insertStr = "";
String currentLine;
while ((currentLine = insertReader.readLine()) != null) {
if (currentLine.length() != 0) {
if (currentLine.charAt(currentLine.length() - 1) == ';') {
insertInDb(db, insertStr + "\n" + currentLine);
insertStr = "";
} else {
insertStr += currentLine;
}
}
}
}
db.setTransactionSuccessful();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (insertReader != null) {
try {
insertReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
db.endTransaction();
}
return result;
}
private void insertInDb(SQLiteDatabase db, String assetFilePath) throws IOException {
if (assetFilePath != null && assetFilePath.length() > 0) {
SQLiteStatement statement = db.compileStatement(assetFilePath);
statement.execute();
}
}
I used this technique to insert 4000 records in db. And it was working fine without much of the lag. If anyone have any batter solution for it. Kindly post it.

Java Gui Text files Output

try {
String hour = (String) comboBox.getSelectedItem();
String filename = fileName.getText();
String date = ((JTextField)dateChooser.getDateEditor().getUiComponent()).getText();
String text = txtKeyword.getText();
String newline = "\n";
String directory = Directory.getText();
File path = new File(directory);
File[] faFiles = path.listFiles();
for(File file: faFiles){
**if(file.getName().contains(filename + "-" + date + "[" + hour + "]") == true == true || file.getName().contains(filename + "-" + date) || file.getName().contains(filename)){**
String line = null;
Reader reader = new InputStreamReader(new FileInputStream(file), "utf-8");
BufferedReader br = new BufferedReader(reader);
while ((line = br.readLine()) != null) {
if(line.contains(text)){
jTextArea1.append(line + newline);
btnClear.setEnabled(true);
btnExport.setEnabled(true);
}
}
br.close();
}
}
}
catch(Exception e){
}
Here is my question. I'm trying to use input and loop method to search for a file. The above code works but my problem is lets say I try to find 2 different text files
1. billing-20140527[09].txt has
a)XGMS,2014-05-27 10:08:04,122,PLAYER_VERIFY,VERIFY to LBA,0x580000,0xC0000,253040.
b)XGMS,2034-05-27 30:08:04,122,PLAYER_VERIFY,VERIFY to LBA,0x580000,0xC0000,253040.
2. billing-20140527[10].txt has
a)XCGS,2014-05-27 10:08:04,122,PLAYER_VERIFY,VERIFY to LBA,0x580000,0xC0000,253040.
b)HELO
**I try to find the number 1 in both text files, if lets say I input the text file name is
billing, I can find the number 1 in both text file and output them:**
a) XGMS,2014-05-27 10:08:04,122,PLAYER_VERIFY,VERIFY to LBA,0x580000,0xC0000,253040.
b) XCGS,2014-05-27 10:08:04,122,PLAYER_VERIFY,VERIFY to LBA,0x580000,0xC0000,253040.
**However, if I specify the text file name: billing-20140527[09].txt and find the number 1 inside the text file, it will only output:
a) XGMS,2014-05-27 10:08:04,122,PLAYER_VERIFY,VERIFY to LBA,0x580000,0xC0000,253040.**
Can anyone help me with this? Guide or help?
I would work with the BufferedReader. Because it reads a whole line. And then you can split the line by a delimiter (lets say a space " " ). In your case I would write a split-method which receives a String and search for the regex you want.
private void doSearch(File f2) throws IOException,
fileHandler.FileException {
File[] children = f2.listFiles();
if (children != null && searching)
for (int i = 0; i < children.length; i++) {
if (g.isReady()) {
g.setReady(false);
if (!searching) {
g.setReady(true);
break;
} else if (isDirectory(children[i])) {
g.getActualDirectoryInhalt().setText(children[i].getPath()
.substring(g.root.getText().length()));
counterDirectories++;
doSearch(children[i]);
} else if (advancedSearch && !filterSpecified(children[i])) {
raiseCounterForDirectorySize(children[i]);
continue;
} else if (checkFile(children[i])) {
counterFiles++;
searchThroughFile(children[i], this.regex);
raiseCounterForDirectorySize(children[i]);
} else {
g.getTextAreaUnreachable().setText(
g.getTextAreaUnreachable().getText() + f2
+ "\n");
raiseCounterForDirectorySize(children[i]);
}
} else {
doSearch(children[i]);
}
g.setReady(true);
}
}
And here's the other method:
public static void searchThroughFile(File f2, String regex) throws IOException,
fileHandler.FileException {
try {
InputStream is = new BufferedInputStream(new FileInputStream(f2));
String mimeType = URLConnection.guessContentTypeFromStream(is);
ArrayList<String> linesFromFile = fileHandler.FileReaderer
.readFileIntoStringArrayList(f2);
String line = null;
if (f2.getAbsolutePath().contains(regex)) {
g.getTextAreaAdvanced()
.setText(
g.getTextAreaAdvanced().getText()
+ f2.getPath() + "\n");
}
if (linesFromFile.size() != 0) {
for (int i = 0; i < linesFromFile.size(); i++) {
line = linesFromFile.get(i);
Pattern MY_Pattern = Pattern.compile(regex);
Matcher m = MY_Pattern.matcher(line);
if (!searching) {
break;
}
MarkOne: if (!g.isReady()) {
break MarkOne;
} else {
g.setReady(false);
}
while (m.find() && searching) {
counterFoundPattern++;
g.getFoundFilesInhalt().setText(counterFoundPattern + "");
if (mimeType != null) {
g.getTextAreaAdvanced().setText(
g.getTextAreaAdvanced().getText()
+ f2.getPath() + " " + m.group()
+ " " + mimeType + " " + i+1 + "\n");
} else {
g.getTextAreaAdvanced().setText(
g.getTextAreaAdvanced().getText()
+ f2.getPath() + " " + m.group()
+ " " + i+1 + "\n");
}
}
g.setReady(true);
}
}
} catch (IOException e) {
MarkOne: if (!g.isReady()) {
break MarkOne;
} else {
g.setReady(false);
}
g.getTabpane().setForegroundAt(2, Color.RED);
g.getTextAreaException().setText(
g.getTextAreaException().getText() + e + "\n");
g.setReady(true);
} catch (OutOfMemoryError oute) {
MarkOne: if (!g.isReady()) {
break MarkOne;
} else {
g.setReady(false);
}
g.getTextAreaException().setText(
g.getTextAreaException().getText() + "\n"
+ "Fatal Error encured! The File will be skipped!"
+ "\n" + f2.getAbsolutePath());
g.getTabpane().setSelectedIndex(2);
g.setReady(true);
return;
}
}

How to write main method for this code?

Okay following is my Simmulation.java file and I am supposed to write main method for it to work. But I have no idea how to do it.
I have tried like following, but it didn't work!
public static void main(String args[])
{
new Simmulation(args[0]);
}
Any help is much appreciated. Thank you in advance
This is my Simmulation.java file
import java.io.File;
import java.util.LinkedList;
import java.util.Queue;
import java.util.*;
import java.util.Scanner;
import java.io.*;
public class Simmulation implements Operation
{
Queue < CashewPallet > inputQueue = new LinkedList < CashewPallet > ();
Stack < CashewPallet > stBay1 = new Stack < CashewPallet > ();
Stack < CashewPallet > stBay2 = new Stack < CashewPallet > ();
FileOutputStream fout4;
PrintWriter pw;
static int tick = 0;
CashewPallet c1;
String temp;
Scanner sc;
public Simmulation(String fn)
{
int index = 0;
String nutType = "";
int id = 0;
Scanner s2;
try
{
sc = new Scanner(new File(fn));
fout4 = new FileOutputStream("nuts.txt");
pw = new PrintWriter(fout4, true);
String eol = System.getProperty("line.separator"); // Reading string line by line
while (sc.hasNextLine())
{
tick++;
s2 = new Scanner(sc.nextLine());
if (s2.hasNext())
{
while (s2.hasNext())
{
String s = s2.next();
if (index == 0)
{
nutType = s;
}
else
{
id = Integer.parseInt(s);
}
index++;
}
System.out.println("Nuttype " + nutType + " Id is " + id + "tick " + tick);
if ((nutType.equalsIgnoreCase("A") || nutType.equalsIgnoreCase("P") || nutType.equalsIgnoreCase("C") || nutType.equalsIgnoreCase("W")) && id != 0)
inputQueue.add(new CashewPallet(nutType.toUpperCase(), id));
System.out.println("Size of Queue " + inputQueue.size());
int k = 0;
if (!inputQueue.isEmpty())
{
while (inputQueue.size() > k)
{
// stBay1.push(inputQueue.poll());
process(inputQueue.poll());
k++;
}
// System.out.println("Size of input "+inputQueue.size() +" Size of stay "+stBay1.size());
}
}
else
{
fout4.write(" ".getBytes());
}
index = 0;
if (!stBay2.isEmpty())
{
while (!stBay2.isEmpty())
{
c1 = stBay2.pop();
temp = tick + " " + c1.getNutType() + " " + c1.getId() + eol;
fout4.write(temp.getBytes());
}
// System.out.println("Nut final "+ stBay2.peek().getNutType());
}
else
{
temp = tick + eol;
fout4.write(temp.getBytes());
}
}
}
catch (Exception e)
{
System.out.println("Exception " + e);
}
closeStream();
}
public CashewPallet process(CashewPallet c)
{
// CashewPallet c=new CashewPallet();
int k = 0;
// while(stBay.size()>k)
// {
// c=stBay.pop();
String operation = c.getNutType();
if (c.getPriority() == 1)
{
shelling(c);
washing(c);
packing(c);
//stBay2.push(c);
}
else
{
switch (operation)
{
case "A":
shelling(c);
washing(c);
packing(c);
break;
case "C":
washing(c);
packing(c);
break;
case "W":
washing(c);
shelling(c);
packing(c);
break;
}
}
return c;
}
public void closeStream()
{
try
{
fout4.close();
}
catch (Exception e)
{
}
}
public boolean shelling(CashewPallet c)
{
// for(int i=0;i<20; i++)
{
System.out.println("Performing Shelling for " + c.getNutType());
}
return true;
}
public boolean washing(CashewPallet c)
{
// for(int i=0;i<20; i++)
{
System.out.println("Performing Washing for " + c.getNutType());
}
return true;
}
public boolean packing(CashewPallet c)
{
// for(int i=0;i<20; i++)
{
System.out.println("Performing Packing for " + c.getNutType());
}
stBay2.push(c);
return true;
}
The problem is that you are not passing any parameters to the program. So the length of the args is 0. What you can try is to check for the length of the args passed before using it.
if (args.length > 0)
new Simulation(args[0]);
else
new Simulation("Default value");
That should solve your problem.

Categories