Advertisement
Mastermindzh

Helpmij.nl - TXT of CSV invoegen

Aug 5th, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.FileInputStream;
  3. import java.io.InputStreamReader;
  4. import java.io.PrintWriter;
  5.  
  6.  
  7. public class ReadCSV {
  8.  
  9.     public ReadCSV(String path){
  10.         // Open the file
  11.         try{
  12.             FileInputStream fstream = new FileInputStream(path);
  13.             BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
  14.  
  15.             String strLine;
  16.             PrintWriter writer = new PrintWriter("export.sql", "UTF-8");
  17.             writer.println("INSERT INTO `michaelwijnands_lv`.`clients` (`user_name`, `company`, `email`, `serial_no`, `additional_information`) VALUES ");
  18.            
  19.             //Read File Line By Line
  20.             int counter = 0;
  21.             while ((strLine = br.readLine()) != null)   {
  22.               // Print the content on the console
  23.            
  24.               System.out.println (strLine);
  25.               writer.println("('naam"+counter+"','company"+counter+"','mail"+counter+"@michaelwijnands.nl','"+strLine+"','extra-info"+counter+"'),");
  26.               counter++;
  27.             }
  28.  
  29.             //Close the input stream
  30.             br.close();
  31.             writer.close();
  32.         }catch(Exception e){
  33.             System.out.println(e.getMessage());
  34.         }
  35.             }
  36.     public static void main(String[] args){
  37.         if(args.length > 0){
  38.             new ReadCSV(args[0]);
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement