convert .txt file in .csv format 1 Answer(s) 3 years and 2 months ago
Posted in : Java Beginners
Dear all,
I hope you are doing good. I am looking to convert .txt file in .csv format. The contents might have different names and values. e.g.
start: id:XXXX name:abc address:xyz
start: age:29 height:5'9
start: accountno:xxx emailid:xxxxx
end:
I want export these contents to a .csv file. I am aware that I need to use delimiter. But I am not getting the exact out put I do wish to. This is what I thought I should do.
1.look for the start: 2.once you catch first start:, look for the name:value pair using : delimiter. 3.store this name:value pair in local variable like string etc. 4.repeat the steps until we see end: 5.extract the name:value pair in a .csv file.
I am interested in message at console. At the same time, I also want the stored name:value pairs should be exported to .csv file and I should be able to display contents of the .csv file.
This is what I have written so far. [code] import java.util.regex.*; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileNotFoundException; import java.io.IOException;
public class fileRead { public static void main(String[] args) { File file = new File("C:\\source1.txt"); StringBuilder sb = new StringBuilder(); String line=null;
try { BufferedReader reader = new BufferedReader(new FileReader(file)); String text = null;
// repeat until all lines is read while ((line = reader.readLine()) != null) { if(!line.trim().equals("")) { if(line.startsWith("begin:")) { String[] data = sb.toString().trim().split("\n");
public class TextToCSV { public static void main (String[] args) throws Exception { try{ FileInputStream fstream = new FileInputStream("C:\\data.txt"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; ArrayList list=new ArrayList(); while ((strLine = br.readLine()) != null){ list.add(strLine); } String id="",name="",course="",deptt="";
int index=1; for (itr=list.iterator(); itr.hasNext(); ){ String str=itr.next().toString(); String [] splitSt =str.split(" "); for (int i = 0 ; i < splitSt.length ; i++) { id=splitSt[0]; name=splitSt[1]; course=splitSt[2]; deptt=splitSt[3]; } HSSFRow row = sheet.createRow((short)index); row.createCell((short)0).setCellValue(id); row.createCell((short)1).setCellValue(name); row.createCell((short)2).setCellValue(course); row.createCell((short)3).setCellValue(deptt); index++; }
FileOutputStream fileOut = new FileOutputStream("c:\\TextToCSV.xls"); wb.write(fileOut); fileOut.close(); System.out.println("Data is saved in excel file."); } catch(Exception e){System.out.println(e);} } }
Thanks
Related Pages:
convert .txt file in .csv format - Java Beginners convert .txtfile in .csv format Dear all,
I hope you are doing good.
I am looking to convert .txtfile in .csvformat.
The contents might have... want export these contents to a .csvfile. I am aware that I need to use
txt to cvs format
);
//convert(outpath);
}
}
Java convert text file to CSVfile... file from one directory and writes an new one in cvs format in another one. I am...();
}
//this class converts the text file into binary
static void convert(String to_convert
Convert CSV to excel File - Java Beginners ConvertCSV to excel File Sir,
i have CSVfile as input. I need to convert that CSVfile to excel file and format.
Currently i am using HSSF POI api to format the excel file. Here i am unable to read the data from the CSV
How create csv format in jsf ?
the pdf file now I want to create .csvformat using this data ?
Please Help me...How create csvformat in jsf ? Dear Friends , Good morning to all of you?
I have a problem to create .CSVformat in jsf. Actully I have
Uploading and download pdf or .txt file.
Uploading and download pdf or .txtfile. I want admin user to upload pdf file into database and the users can download those pdf format from database
csv file download csvfile download Hello Every one,
when user clicks download button I want to retrieve data from mysql database table in csvformat using java.if you know please send code.
Thanks in Advance
Please visit
Shifting txt file to database - Java Beginners
Shifting txtfile to database Question Details:
I want to shift data from txtfile to Database. The data is written in the following text format.
Record No. = 0001
Name : Abdul Rauf
Designation
How to import txt file using SQL
How to import txtfile using SQL Hai, I have a log file in .txtformat and format of the log is given below. From the log i want to pick up some particular words and insert onto a table using SQL. I want the output of the table
Thread for reading txt file
Thread for reading txt file how to use 3 thread to read 3 txtfile?
To create three threads for reading the file and three threads for getting the strings out of the queue and printing them.
thanks
Retrieve Data from CSV file in JSP
Retrieve Data from CSVfile in JSP
CSVfile : A CSVfile is commonly known as a Comma... a Page ("ReadCsvFile.jsp") to retrieve the data from CSVfile
"
How to convert EBCDIC format value into ASCII format value in java
How to convert EBCDIC format value into ASCII format value in java how to convert EBCDIC data format into ASCII format data using java
Use Case:I my file contains ASCII format values as well as EBCDIC format values.I need
SQL Bulk Insert csv
respectively.Again, we create a file abc with extension csv
contain the records...
SQL Bulk Insert csv
SQL Bulk Insert is used to import the records from csv file
Convert pdf to rtf and txt - XML Convert pdf to rtf and txt Can we convert PDF to RTF and TXT, and how? Hi Friend,
Try the following codes:
1)Convert PDF to RTF...) {}
}
}
2)Convert PDF to TEXT
import java.io.*;
import java.util.
Export Database table to CSV File
Export Database table to CSVFile
In this tutorial, you will learn how to retrieve data from database and save
it to CSVFile.
The Comma-separated values, better knows as CSV is having a delimited data
format. It has field/columns
Backup Into txt File
Backup Into txtFile
Backup Into txtFile is used to put the backup file from a ... illustrate an example from 'Backup Into txtFile'. To
understand this example
How to convert multiple files in java to .zip format
How to convert multiple files in java to .zip format i receive...);
}
i want to convert the data from inputStream into Zip Stream and so...;
protected void createZip(File zipFile, File[] listFiles) {
try {
byte b
To Upload and insert the CSV file into Database
To Upload and insert the CSVfile into Database... to upload a CSVfile through JSP and
insert it into the database. For this, we have...()
is defined to convert the whole content of file into String.
To insert this file
.csv file to databse
.csvfile to databse I have an 1 .csvfile.. its having the url values like http://maps.google.com/?q=425+Bingeman+Centre+Drive%2c+chrompet%2c+ON%2c+600+006... q is request parameter .425 Bingeman Centre Drive is address
How to write into CSV file in Java
How to write into CSVfile in Java How to write into CSVfile in Java
Hi,
To create Comma separated value(CSV) file is very simple and the CSVfile stores the value in the tabular form i.e. rows and columns
Export data into CSV File using Servlet
Export data into CSVFile using Servlet
 ... to Export data
into CSVfile
using Servlet. We have created file "... description for the flow of application :
A CSVfile is commonly known as a Comma
Backup selected records into txt file
Backup selected records into txtfile
Backup selected records into txtfile is used to copies... into txtfile.
To restore the selected backup records into txtfile, we create
how to change file from .txt to .mat(matrix)
how to change file from .txt to .mat(matrix) i have a big file.txt and i want to change this file to file.mat(matrix) ...this is in windows not on any os ..thx if u answering quickly please
Backup Into txt File
Backup Into txtFile
Backup Into txtFile is used to put the backup file from a ... illustrate an example from 'Backup Into txtFile'. To
understand this example
Mysql CSV file into database. Mysql CSV is used to load the text file and add
to the table... that has same format as of text file g.csv.
data inline : The keyword is used... data from csvfile:
mysql> load data infile "C:/g.csv
problem while reading .csv file
problem while reading .csv file I have a problem here.....
i am reading a .csv extention file which has some value....but the problem is der is an amount column which contains , in between (eg) 3,899.00
which inturns creates
Java Read CSV file
Java Read CSVfile
In this tutorial, you will learn how to read csvfile.
CSV... to break the line using ",". The delimiter for a CSVfile is a comma....
Here is a csvfile:
Example
import java.io.*;
import java.util.*;
public
Java Write To File CSV
Java Write To FileCSV
In this tutorial you will learn how to write to file... that
is in a tabular form. In java to create a csvfile is simple, you would require... a simple example which will demonstrate you how to write to
csvfile. To achieve
Adding .txt files in a given directory
tag value as one .txtfile in a given directory? I have extracted tag values but plz help me how can I save each body tag as one .txtfile and add in a directory...Adding .txt files in a given directory I want to read number of XML
Remove JTable row that read txt file records
Remove JTable row that read txtfile records Hi every one.
i have a jtable that correctly read data frome file and show them in own.
I want to add a "Delete" button that when select a row and clicked button, row must deleted
reading a csv file from a particular row
reading a csvfile from a particular row how to read a csvfile from a particular row and storing data to sql server by using jsp servlet
Backup selected records into txt file
Backup selected records into txtfile
Backup selected records into txtfile is used to copies... into txtfile.
To restore the selected backup records into txtfile, we create
how to parse a csv file using standard libraries?
how to parse a csvfile using standard libraries? hie i am a beginner in java i want to parse a csvfile using any standard libraries i want to know how the libraries are imported and used in eclipse thanks in advance
create csv file in php in multiple columns
create csvfile in php in multiple columns i need create csvfile in multiple columns
like this:
id name age date_added
1 john 23 2012-2-12
2 jane 25 2012-3-14
i can build csvfile like this:
id,name,age,date
create csv file in php in multiple columns
create csvfile in php in multiple columns i need create csvfile in multiple columns
like this:
id name age date_added
1 john 23 2012-2-12
2 jane 25 2012-3-14
i can build csvfile like this:
id,name,age,date
java, upload csv file - Development process
java, upload csv file hi,
i have a csvfile having 29 colums,
i want to upload that csvfile to database.
i need the code,, can u please send me the code..
thanks.. Hi Friend,
Please visit the following
Exporting data from mysql to csv file
to export the data from mysql to csvfile... i am having 30 columns in my database.. Eg- text1,text2,text3,....,upto text30... i want to export this data in csvfile..if i export am getting the csvfile with all data in one row.. but i want the csv
Export Data into CSV file uing JDBC in JSP
Export Data into CSVfile uing JDBC in JSP
CSVfile : A CSVfile is commonly known...();
out.println("<b>You are Successfully Created Csvfile.</b>
php csv file uploding into mysql database table.
php csvfile uploding into mysql database table. hai friends,
i have two excel files with different field names.each files having more than 30... uploding csvfile, i want to fetch the datas in corresponding fields in table.
can
Convert a Character into the ASCII Format Convert a Character into the ASCII Format
In this section, you will learn to convert... the functionality to convert the character
data into the ASCII format
Description
URGENT: Export Table in Oracle db to CSV file
URGENT: Export Table in Oracle db to CSV file Hi,
Could you basically help me by providing a program in Java. I want a program to connect and export a table in the oracle database to a folder in my local harddrive.
Thankyou