Forum     

Go Back   Digit Technology Discussion Forum > Portables, Peripherals and Electronics > QnA (read only)
Register FAQ Calendar Mark Forums Read

QnA (read only) Mods please help transfer the contents of this forum to proper sections. :)


 
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-10-2004, 01:16 AM   #1 (permalink)
Right Off the Assembly Line
 
Join Date: Jul 2004
Posts: 18
Default java help , EOF ...


I am trying to add some strings to EOF my code is as below, but I get an error saying can't convert FileOutPutStream to String




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);
}
Anjali is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 12-10-2004, 01:56 AM   #2 (permalink)
In The Zone
 
#/bin/sh's Avatar
 
Join Date: Apr 2004
Location: 42.65 N 73.76 W
Posts: 213
Default

>>out.println(ticker);

Would appear 'ticker' is not of type String. It needs to be

Points , you simply need to do this:

String ticker = "Something";
// Then the rest of your above code here.
__________________
\"99 little bugs in the code, 99 bugs in the code, fix one bug, compile it again, 148 little bugs in the code. 148 little bugs in the code....\"
#/bin/sh is offline  
Old 12-10-2004, 02:22 AM   #3 (permalink)
Right Off the Assembly Line
 
Join Date: Jul 2004
Posts: 18
Default

Hi
The complie error is in the newTicker.
Anjali is offline  
Old 12-10-2004, 02:32 AM   #4 (permalink)
In The Zone
 
#/bin/sh's Avatar
 
Join Date: Apr 2004
Location: 42.65 N 73.76 W
Posts: 213
Default

Please show where 'ticker' is declared
__________________
\"99 little bugs in the code, 99 bugs in the code, fix one bug, compile it again, 148 little bugs in the code. 148 little bugs in the code....\"
#/bin/sh is offline  
Old 12-10-2004, 03:40 AM   #5 (permalink)
Right Off the Assembly Line
 
Join Date: Jul 2004
Posts: 18
Default

javac -classpath /cad2/corba/JOB-3.3.2/ob/lib/OB.jar:. broker2/*.java
broker2/OnlineBroker.java:116: Incompatible type for constructor. Can't convert java.io.FileOutputStream to java.lang.String.
PrintWriter out = new PrintWriter(new FileWriter(newTicker, true));
^
broker2/OnlineBroker.java:117: Variable ticker may not have been initialized.
out.println(ticker);
Anjali is offline  
Old 12-10-2004, 03:41 AM   #6 (permalink)
Right Off the Assembly Line
 
Join Date: Jul 2004
Posts: 18
Default

public void addSymbol(String symbol) throws broker2.BrokerPackage.BrokerErrorException
{
String ref = null;
String ticker;
String value;
int positionSpace;
boolean foundSymbol = false;

try
{
FileInputStream file = new FileInputStream("nasdaq");
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");
PrintWriter out = new PrintWriter(new FileWriter(newTicker, 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);
}
}*/

}
Anjali is offline  
Old 13-10-2004, 01:08 AM   #7 (permalink)
In The Zone
 
#/bin/sh's Avatar
 
Join Date: Apr 2004
Location: 42.65 N 73.76 W
Posts: 213
Default

Please say what happens when you do, instead of

>>PrintWriter out = new PrintWriter(new FileWriter(newTicker, true));


java.io.PrintWriter out = new java.io.PrintWriter(new java.io.FileWriter(newTicker, true));
__________________
\"99 little bugs in the code, 99 bugs in the code, fix one bug, compile it again, 148 little bugs in the code. 148 little bugs in the code....\"
#/bin/sh is offline  
Old 13-10-2004, 01:10 AM   #8 (permalink)
In The Zone
 
#/bin/sh's Avatar
 
Join Date: Apr 2004
Location: 42.65 N 73.76 W
Posts: 213
Default

Oh and

java.io.FileOutputStream newTicker = new java.io.FileOutputStream("nasdaq");
__________________
\"99 little bugs in the code, 99 bugs in the code, fix one bug, compile it again, 148 little bugs in the code. 148 little bugs in the code....\"
#/bin/sh is offline  
Old 13-10-2004, 02:23 AM   #9 (permalink)
Right Off the Assembly Line
 
Join Date: Jul 2004
Posts: 18
Default

Hi

I get the same error:

javac -classpath /cad2/corba/JOB-3.3.2/ob/lib/OB.jar:. broker2/*.java
broker2/OnlineBroker.java:116: Incompatible type for constructor. Can't convert java.io.FileOutputStream to java.lang.String.
java.io.PrintWriter out = new java.io.PrintWriter(new java.io.FileWriter(newTicker, true));

^
Anjali is offline  
Old 13-10-2004, 02:48 AM   #10 (permalink)
In The Zone
 
#/bin/sh's Avatar
 
Join Date: Apr 2004
Location: 42.65 N 73.76 W
Posts: 213
Default

Try
PrintWriter out = new PrintWriter(new FileOutputStream("nasdaq"), true);
__________________
\"99 little bugs in the code, 99 bugs in the code, fix one bug, compile it again, 148 little bugs in the code. 148 little bugs in the code....\"
#/bin/sh is offline  
Old 13-10-2004, 09:08 AM   #11 (permalink)
Broken In
 
Join Date: Jul 2004
Location: Somewhere In my room....
Posts: 143
Default 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!!
__________________
\"Hating people is like burning down your own house to get rid of a rat\" - Harry Emerson Fosdick
\"A Pessimist is one who makes difficulties of his oppertunities; an optimist is one who makes oppertunities of his difficulties\" - Reginald B. Mansell
oh yeah.. my Fav Quote
\"Sometimes a winner is just a dreamer who never gave up.\"
allajunaki is offline  
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by clmlbx
- by Sujeet
- by gforz

Advertisement




All times are GMT +5.5. The time now is 03:38 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2