Java Eclipse output to csv file - java

I'd like to redirect my Java Eclipse's console output to a CSV file.
I know how to do that for a TXT file (Run Configurations-Common-etc.), but I can't find how to get a CSV file.
Thanks a lot.

There is no support for this in Eclipse.
Console output is generally not in a format suitable for a CSV file. It is up to you to add code to your program to generate the correct format for CSV.

I dont know if it helps, but csv is basicly txt. You can separate your output by ";" in compile time, output it to txt and then just save it like CSV.

I think whatever you are printing on the console, you can just use one of these solutions to write it in CSV format and that's pretty much it.
1> Simple Solution: If you are sure the CSV files doesn’t contain “separator or double-quotes”, just use the standard split() to parse the CSV file.
2> Advance Solution: This solution will solve the field containing “separator or double-quotes” issue, and also support the custom separator and custom enclosed field. Review the following CSV parsing example and also the JUnit test cases to understand how it works.
3> OpenCSV Example: If you are not comfortable with above simple and advance solution, try using third party CSV library – OpenCSV.
https://www.mkyong.com/java/how-to-read-and-parse-csv-file-in-java/

Don't use System.out.println() but define a PrintStream that you use somewhere, so it becomes myOut.println().
Or better, use a logger-library for it, for example log4j, or even a facade: slf4j

Related

Using the code to input data for backpropagation

I am learning to build neural nets and I came across this code on github,
https://github.com/PavelJunek/back-propagation-java
There is a training set and a validation set required to be used but I don't know where to input the files. The Readme doesn't quite explain how to use the files. How do I test with different csv files I have on this code?
How so? It tells you exactly what to do. The program needs to get two CSV files: a CSV file containing all the training data and a second CSV file containing all of the validation data.
If you have a look at the Program.java file (in the main method), you'll see that you need to pass both files as arguments with the command line.

Extract text from PCL6 using Java

I don't have much knowledge regarding PCL6 file format. I wanted to know if there is any way to extract text out of PCL6 file using Java.
Thanks,
Usman
Convert the file to PDF (see Ghostscript/GhostPDL) and then use Apache Tika.
The first step will require to use some Runtime.getRuntime().exec(...)

How to read pig output in separate Java program

I have some pig output files and want to read them on another machine(without hadoop installation). I just want to read a tab-seperated plain text line and parse it into a java object. I am guessing we should be able to use pig.jar as dependency and be able to read it. I could not find relevant documentation. I think this class could be used? How can we provide the schema also.
I suggest you to store data in Avro serialization format. It is Pig-independent and it allows to handle complex data structures like you described (so you don't need to write your own parser). See this article for examples.
Your pig output files are just text files, right? Then you don't need any pig or hadoop jars.
Last time i worked with Pig was on amazon's EMR platform, and the output files were stashed in an s3 bucket. They were just text files and standard java can read the file in.
That class you referenced is for reading into pig from some text format.
Are you asking for a library to parse the pig data model into java objects? I.e. the text representation of tuples & bags, etc? If so then its probably easier to write it yourself. It's a VERY simple data model with only 3 -ish datatypes..

Importing a CSV File into Java

In the program I am writing, I want to be able to import CSV files. At the moment, it takes a basic text file in.
File mainemails = new File ("mainemails.txt");
I know that for CSV imports using File is probably not the most time-efficient thing to use. What would be the most efficient way to import a CSV file? Would I have to download any new libraries to use an efficient method?
You can use opencsv for importing csv data and then constructing objects from it.
I prefer using libraries so that I can save development time. Also they tend to solve specific problems better.
Try OpenCSV as suggested here and here.

How to read excel file and convert it to tab delimited file with java

I have a directory where files are constantly updated. I need to read the latest excel file and convert it into tab delimited file. It is under windows. A batch + java solution will work for me. Or if I can use excel in command line programatically that also works
I would disagree with those people who recommend Apache POI. The best API that I know of for dealing with Excel is Andy Khan's JExcel.
It has already been widely suggested, POI is probably the most complete "pure Java" implementation of Excel.
In one API you get support for Excel 2003 and 2007.
However, you need to be weary of its memory footprint. It is a hog. If you use it, make sure you use the event-driven model it supports as this will reduce footprint and execute faster.
In Java you can use, for example, Apache POI library to read data from Excel files. And then use standard Java facilities to write data into tab delimited file.
You can read in the excel sheet using POI and then iterate through the cells, writing them out to a separate file with appropriate delimiters.
Have a look at other SQ question: convert Excel to csv either using shell script or jython . if so how
I answered with PyODConverter, but there is jodconverter: Java version of this tool. It uses OpenOffice working as a service. I use it to convert between various file formats.
You can use Apache POI API for reading the excel file and OpenCSV for writing the CSV file.

Categories

Resources