This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Create Excel file in Java
How to save output in excel format rather than in .txt file?
A great alternative to an actual excel file is a CSV file which stands for Comma Separated Values. Basically you output your data as follows:
First Name, Last Name, Birthday
Joe, Smith, 10/10/78
Matt, Jones, 2/2/90
With commas between each column, and newlines after each row. If your data has commas in it, you can enclose the data in quotes.
Excel has very good support for loading csv files, and you can even use them as a linked data source in an excel file, and then reference the data from other sheets for graphing, calculations, and pivot tables.
Related
This question already has answers here:
Reading a plain text file in Java
(31 answers)
Closed 4 years ago.
So I need to read multiple lines of text from a file in Java, for example a txt file record of peoples names height age etc.
I then need to print certain lines from the file, and certain columns, and then sort them based on tallest/oldest etc. How would I go about doing this?
I think I need to put the data from the txt file into an array? But not quite sure.
if I understood the problem, you can create a Class called Person (os something else as you wish) with all the data that you have. than read the file using a Scanner and for each line you can instantiate a new Person and add it to an ArrayList. after you finish reading all the lines from your file, you can use Collections.sort() (you can use the one with a Comparator or use the natural ordering).
links to Collections.sort Javadoc
https://docs.oracle.com/javase/6/docs/api/java/util/Collections.html#sort(java.util.List)
https://docs.oracle.com/javase/6/docs/api/java/util/Collections.html#sort(java.util.List,%20java.util.Comparator)
This question already has answers here:
Converting an CSV file to a JSON object in Java
(9 answers)
Closed 6 years ago.
This is my CSV file:
no name id
1 yog a122
2 nik b122
I want convert this file in json using java. I tried javascript, jsp,
servlet but didn't get output.
I think you need to bit more googling on this, that is pretty much famous question.
Please check following link
https://github.com/FasterXML/jackson-dataformat-csv
And also following stack overflow post
directly convert CSV file to JSON file using the Jackson library
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
i have a text file which contains 100000 line as below
be3c152f6f6bcd5 AL9 60 51.7458349055774 -0.191050898942398 F
be3c15cd5 AL9 30 51.79055774 -0.191050898942398 M
now i have to create a design where i need to read all this and based on test condition
needs to generate the output in same file format which i read
i was thinking this to implement by
reading all lines of input file
keeping them in List<some pojo>
now this pojo will have reference to all condition and generate the o\p
my question is loop readline 1 l00000 times and generate the pojo is good or not ?Also in the final o\p folder for each test case condition i have to convert this List<pojo to text format as above what we read.
please let me know some better way.
Read line, process line, write line. No need to keep them all in memory.
It's a simple problem for parsing records.
You don't want each line in a List; you want the POJO containing the data after you tokenize each line.
Here's pseudo-code:
Open file
Loop over all lines in file
Tokenize each line and populate POJO
Add POJO to List
Close file
Perform any operations you wish on POJOs
Output POJO List in desired format
If it's just tab delimited, perhaps you can use a library that already deals with .csv files.
I assume, the test conditions only depend on one line at a time:
You should stream the data both in and out.
After processing the first line - which consists of reading and parsing - check the conditions. If the line should be kept in the output, you can now stream it to the (different) output file. If it should be deleted, you can just ignore it and skip to the next line of the input.
It sounds like a good idea to create an Element which has the different columns of the file as fields. You could then overwrite to String to generate the desired output and a Constructor which takes the String in the input Format to parse it.
This question already has answers here:
CSV API for Java [closed]
(10 answers)
Closed 9 years ago.
What is the best CSV java library to parse bank statements. Is there any standard csv format for bank statements? Where can i get the sample files?
I use openCSV.
Very easy to use, see the examples:
http://opencsv.sourceforge.net/#how-to-read
Parsing bank statements in csv is as good as parsing any other csv file.
I always rely on OpenCsv.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Concatenating WAV files in Java
What's the simplest way to concatenate more than two WAV files in Java?
If you're asking about concatenating more than two, I'll assume that you already have a way to concatenate exactly two.
In which case you can concatenate multiple files together by simply concatenating each file in turn to the rolling total. Something like this (for four files):
concatenate(concatenate(concatenate(wav1, wav2), wav3), wav4);