Have to write Java code to Select CSV File or Text file from Computer and Split into multiple files.. based on field information.. Split file by State
Please help me!!
Example:
robert.txt select this file..
FirstName,LastName,Address1,Address2,City,State,Zi p
robert,paul,windihill,,fort myers,FL,30907
rathin,das,oakbook,apt:2453,fort myers,FL,30907
Joshua,Arem,160 Crestwood Ct,,Alpharetta,GA,30067
Soak,Yang,1335 Kilmington Ct,,Alpharetta,GA,30009
Zerita,Washington,845 Regal Path Ln,Decatur,TN,30087
Zerita,Washington,845 Regal Path Ln,Decatur,TN,30004
......
.......
......
....
Split files..
1) robert_state_FL
FirstName,LastName,Address1,Address2,City,State,Zi p
robert,paul,windihill,,fort myers,FL,30907
rathin,das,oakbook,apt:2453,fort myers,FL,30907
2) robert_state_GA
FirstName,LastName,Address1,Address2,City,State,Zi p
Joshua,Arem,160 Crestwood Ct,,Alpharetta,GA,30067
Soak,Yang,1335 Kilmington Ct,,Alpharetta,GA,30009
3) robert_state_TN
FirstName,LastName,Address1,Address2,City,State,Zi p
Zerita,Washington,845 Regal Path Ln,Decatur,TN,30087
Zerita,Washington,845 Regal Path Ln,Decatur,TN,30004
...
...
--------------------
Trying to do this!!
package com.mkyong.io; import javax.swing.JFileChooser; import javax.swing.filechooser.FileNameExtensionFilter; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; public class split { public static void main(String[] args)throws Exception { JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter ("Text/Java files", "txt", "java"); chooser.setFileFilter(filter); int returnVal = chooser.showOpenDialog(null); if(returnVal == JFileChooser.APPROVE_OPTION) { File f = chooser.getSelectedFile(); BufferedReader br = new BufferedReader (new FileReader(f)); String st = ""; while((st = br.readLine()) != null) { System.out.println(st); } } } }
I know how to choose text file from computer and read that.. but.. I don't know next please help me..