Hi there,
I'm currently trying to get a class to download a history of stock prices. I can connect to the site and download the CSV however there is a problem in that on each line of the output CSV i would like to also add the name of the stock or simply the the stock ticker. I'm running into trouble because the inputStream and outputStream are in bytes so I'm not exactly sure how to add a String at the beginning of each line. I've tried reading through the API and searching in Goole but the only thing I come up with are converters from outputStream to inputStream.
URL httpAddressAndFileName;
try {
httpAddressAndFileName =
new URL("http://ichart.finance.yahoo.com/table.csv?s=" + tickerSymbol +
"&a=03&b=1&c=2000&d=07&e=15&f=2006&g=d&ignore=.csv");
} catch (MalformedURLException e) {
System.out.println("Error while generating home page URL: " +
e.getMessage());
return;
}
File directoryAndFileName = new File("C:/Downloads/NYSE Daily Download/NYSE5Y.csv");
try {
InputStream inputStream = httpAddressAndFileName.openStream();
OutputStream outputStream = new FileOutputStream(directoryAndFileName,true);
int i;
byte buff[] = new byte[1024 * 16];
while ((i = inputStream.read(buff)) >= 0) {
I would like to possibly add an if statement checking if its the end of the line and then first writing the name of the stock tickerThe probllme is that I'm not sure how to test if a byte is a end of line character. The byte to insert can be an istatiation of the Byte class but here again I'm not entirely sure because I've never really delt with bytes.
outputStream.write(buff, 0, i);
}
outputStream.close();
inputStream.close();
} catch (FileNotFoundException e) {
JOptionPane.showMessageDialog(null, e.getMessage(),
"File Not Found Error",
JOptionPane.ERROR_MESSAGE);
} catch (IOException e) {
JOptionPane.showMessageDialog(null, e.getMessage(), "IO Error",
JOptionPane.ERROR_MESSAGE);
}