Ok I think i cracked it...
I think The problem lies in the fact that
there is no Overloaded constructor for FileWriter in java which takes FileOutputStream as constructor...
so may wanna modify the statement to directly open the file in FileWriter , instead of Plugging the file into a stream and then plugging Stream to FileWriter
instead of
File.nasdaq->
FileOutputStream.newTicker->FileWriter->PrintWriter
eliminate the underlined part....
So ur code becomes something like this
Code:
//add symbol to the EOF
try
{
//FileOutputStream newTicker = new FileOutputStream("nasdaq");
// FileOutputStream not required
//PrintWriter out = new PrintWriter(new FileWriter(newTicker, true));
// Invalid FileWriter Constructor, Valid constructors are the ones that take File,String,FileDescription ).
PrintWriter out = new PrintWriter(new FileWriter("nasdaq", true));
out.println(ticker);
out.close();
}
See if this helps ya!!
(I copy pasted ur prog, hacked it a lil to make the snippet work independantly and got it working this way... Hope this helps....)
Now if u r interested here is the complete Code Base that a worked on...
See it for urself...
Code:
import java.io.*;
import java.io.File;
public class javaFile
{
public javaFile()
{
}
public void addSymbol(String symbol) throws IOException
{
String ref = null;
String ticker = symbol;
String value;
int positionSpace;
boolean foundSymbol = false;
try
{
FileInputStream file = new FileInputStream("nasdaq.txt");
BufferedReader in = new BufferedReader(new InputStreamReader(file));
/* while((ref = in.readLine())!=null)
{
positionSpace = ref.indexOf(' ');
ticker = ref.substring(0, positionSpace);
value = ref.substring(positionSpace+1);
if(ticker.equalsIgnoreCase(symbol))
{
broker2.BrokerPackage.BrokerErrorException err = new
broker2.BrokerPackage.BrokerErrorException(broker2.BrokerPackage.BrokerErrors.SymbolExists);
throw err;
}
else
{
foundSymbol = false;
//FileOutputStream newTicker = new FileOutputStream("nasdaq");
//System.out.println("adding symbol\n");
//PrintWriter out = new PrintWriter(new FileWriter("nasdaq", true));
//out.println(ticker);
//out.close();
}
}
if ( foundSymbol == false)
{
*/
//add symbol to the EOF
try
{
//FileOutputStream newTicker = new FileOutputStream("nasdaq.txt");
PrintWriter out = new PrintWriter(new FileWriter("nasdaq.txt", true));
out.println(ticker);
out.close();
}
catch (IOException e)
{
System.err.println(e.getMessage());
System.exit(1);
}
// }
file.close();
}
catch (IOException e)
{
System.err.println(e.getMessage());
System.exit(1);
}
/*if ( foundSymbol == false)
{
//add symbol to the EOF
try
{
FileOutputStream newTicker = new FileOutputStream("nasdaq");
PrintWriter out = new PrintWriter(new FileWriter(newTicker, true));
out.println(ticker);
out.close();
}
catch (IOException e)
{
System.err.println(e.getMessage());
System.exit(1);
}
}*/
}
public static void main(String args[])
{
javaFile x= new javaFile();
try
{
x.addSymbol("cool maan jurenamo");
}
catch(IOException e)
{
System.out.println("Oops!! "+e);
}
}
}
(I created a temp file called nasdaq.txt and then worked on it.. it worked....)
Hope this clears things for ya!!