Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Routing output to different files.

Status
Not open for further replies.

Funkymatt

Programmer
Aug 27, 2002
101
US
I have a vector of transactions. In this vector any given transaction (temp) is either a "D"eliver or an "E"xpect. If the transaction is a deliver I want to output the data into a deliver file and if it's an expect I want to output the data in an expect file.

I have a for loop where check one transaction at a time. This code is also in the for loop:

if (temp.strsafe_tran_type == "D")
{
BufferedWriter out = new BufferedWriter(new FileWriter(delFileName));
}
else if (temp.strsafe_tran_type == "E")
{
BufferedWriter out = new BufferedWriter(new FileWriter(expFileName));
}

//out.write Transaction member data
if (temp.strdepoId == null)
{
out.write("delivery = \"\"" + ",");
}
else
{
out.write("delivery = \"" + temp.strdepoId.trim() + "\"," );
}
out.newLine();

When I complie I'm getting Error: C:\folder\SecWriteToFile.java(50): cannot resolve symbol: variable out in class SecWriteToFile

Is there something that I am not doing that I should or something that I'm doing that I shouldn't?
 
Two problems here ::

1) your "out" variable (BufferedWriter ) is declared inside an "if" statement - and hence the scope of this varibale is restricted to within side this.

2) You will not get successful results using "==" to test for value equality if String objects - its not Javascript ! Try the method .equals() instead.
So ::
Code:
BufferedWriter out = null;
if (temp.strsafe_tran_type.equals("D"))
{
     out = new BufferedWriter(new FileWriter(delFileName));
}
else if (temp.strsafe_tran_type.equals("E"))
{
     out = new BufferedWriter(new FileWriter(expFileName));
}

//.... and the rest
 
outDel = new BufferedWriter(new FileWriter(delFileName));
outExp = new BufferedWriter(new FileWriter(expFileName));

//All transaction modifications performed below. Check the method for details.

//While the vector is not empty, keep looping
for( intCounter =0; intCounter < vecList.size() ; intCounter ++)
{
temp = (SecTxnMaster)vecList.get(intCounter);

if (temp.strsafe_tran_type.equalsIgnoreCase(&quot;D&quot;))
{
out = outDel;
}
else if (temp.strsafe_tran_type.equalsIgnoreCase(&quot;E&quot;))
{
out = outExp;
}
}



Thanks...that's what I ended up going with. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top