vendredi 27 mars 2015

Writing to a file in Java with



I'm trying to print out some stock market information to a file. I take information from a URL, and put that into a csv. Right now it's giving me this error message:


ERROR, make sure no other processes are using dumpFile\DIS.csv and run program again dumpFile\DIS will be skipped or innacurate java.io.FileNotFoundException: dumpFile\DIS.csv (The system cannot find the path specified)


the code in question is this:



DataInputStream in=null;
FileOutputStream fOut = null;
DataOutputStream out = null;
String fileName = getDataFolder()+File.separator+symbol+".csv";

try {
URL remoteFile = new URL(downloadURL);
URLConnection fileStream = remoteFile.openConnection();
in = new DataInputStream(new BufferedInputStream(
fileStream.getInputStream()));

fOut = new FileOutputStream(fileName);
out = new DataOutputStream(new BufferedOutputStream(fOut));

int data;
while ((data = in.read()) != -1) {
out.write(data);
//System.out.println(data);
}
}


The downloadURL variable is the url I want to download from and I know that is correct. The getDataFolder returns "dumpFile". Symbol is the symbol for the company on the stock market, GOOG, DIS, etc... In the call which generated the error message I showed I was calling it with symbol = "DIS". This is mostly code from my prof so I'm not 100% sure how it actually works but I think what it should do is make a file called "dumpFile"+symbol+".csv" and write to that. Am I wrong in that? As to the part about making sure it isn't open somewhere else, I don't have it open anywhere on my computer, I don't even have a file called dumpFile\DIS.csv.




Aucun commentaire:

Enregistrer un commentaire