Advertisement
mrkarp

Untitled

Apr 14th, 2014
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.88 KB | None | 0 0
  1. package Main;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.File;
  5. import java.io.FileNotFoundException;
  6. import java.io.FileReader;
  7. import java.io.IOException;
  8. import java.util.ArrayList;
  9. import java.util.Arrays;
  10. import java.util.List;
  11. import java.util.Scanner;
  12.  
  13. public class ParseAndIterate { 
  14.    
  15.     //Split the array
  16.     static String splitBy = ",";  
  17.     //@init the Read
  18.     static BufferedReader br = null;
  19.     //@init the blank array
  20.     public static String line = "";
  21.    
  22.     //Variables to save
  23.     public static String symbol;
  24.     public static String askPrice;
  25.     public static String bidPrice;
  26.     public static String realPrice;
  27.     public static String volume;
  28.     public static String dividendYield;
  29.    
  30.     static boolean downloadFile = GetFile.downloadFile;
  31.    
  32.     static String csvFile = GetFile.tempFile;
  33.     static List<String> stockInfo = new ArrayList<String>();
  34.     static String[] sqlString;
  35.    
  36.     static boolean parseDone = false;
  37.  
  38.     public static void IterateCSV() {
  39.        
  40.         if(downloadFile == true) {
  41.             try {
  42.                 Scanner s = new Scanner(new File(csvFile));
  43.                 br = new BufferedReader(new FileReader(csvFile));
  44.                 while ((line = br.readLine()) != null) {
  45.                     sqlString = line.split(splitBy);
  46.                     int length = line.length();
  47.                     //System.out.println(line);
  48.                     stockInfo.add(line);
  49.                 }
  50.                 //Close the scanner and buffer
  51.                 br.close();
  52.                 s.close();
  53.  
  54.             } catch (FileNotFoundException e) {
  55.                 e.printStackTrace();
  56.             } catch (IOException e) {
  57.                 e.printStackTrace();
  58.             }
  59.  
  60.             symbol = stockInfo.get(0);
  61.             String sql = Arrays.toString(sqlString);
  62.            
  63.             System.out.println("SQL String: " + sql);
  64.            
  65.             symbol = sqlString[0];
  66.             askPrice = sqlString[1];
  67.             bidPrice = sqlString[2];
  68.             realPrice = sqlString[3];
  69.             volume = sqlString[4];
  70.             dividendYield = sqlString[5];
  71.  
  72.        
  73.             parseDone = true;
  74.             System.out.println("[Parse]: ParseDone: " + parseDone);
  75.  
  76.                 }
  77.             }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement