wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes Need some basic help with converting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Need some basic help with converting" Watch "Need some basic help with converting" New topic
Author

Need some basic help with converting

Rassaad
Greenhorn

Joined: Aug 24, 2001
Posts: 3
A get an error that I can't convert a java.lang.String into a java.io.BufferedReader and that I can't convert a java.io.BufferedReader into a java.lang.String. Any solution in my modifying my code below to get it working

import java.io.*;
import java.util.*;
public class App4 {
public App4 ( ) throws IOException{
//URL anyURL = new URL("http://localhost/anyfile.ext");
//BufferedInputStream buf = new BufferedInputStream(anyURL.openStream());
//BufferedReader br = new BufferedReader(new FileReader(new File("final.txt")));
BufferedReader br = new BufferedReader(new FileReader(new File("data.txt")));
BufferedWriter out = new BufferedWriter(new FileWriter(new File("finalTest.txt")));
StringTokenizer st;
String c="|";
//////////////////////////////////////////////////////////////////////////////////////////////
//Function that I'm thinking of creating to check stream for null values

int j =0;
while ((j=br.readLine().indexOf("| |")) > 0){
StringBuffer sb = new StringBuffer(br);
sb.replace(j,j+2,"|null|");
br = new String(sb);
/* App4.replace(a,aa); //Maybe by modifying this function it might work */
}
//Verify output
System.out.println(br);
/////////////////////////////////////////////////////////////////////////////////////////////
int temp;

while(true){
if( (c=br.readLine()) == null) break;
st = new StringTokenizer(c);
temp = st.countTokens();
for(int i = 0; i < (temp+1); i++){

if(i!=0){
//out.write(" " + st.nextToken());
System.out.print(" " + st.nextToken());
} else {
//out.newLine();
System.out.println(" ");
}
} //for
} //while

out.flush();
br.close();
out.close();
} //end of constructor
public static void main ( String args[] ) throws IOException {
new App4();
}//End of Main Method

// Another option would be to use this function
/////////////////////////////////////////////////////////////////////////////////
//This function should loop by replacing a value for another value
/* public String replace(char oldChar, char newChar)
{
char[] buff = new char[value.length];
boolean found = false;
for (int i = 0; i < value.length; i++)
{
char c = value[i];
if (c == oldChar)
{
found = true;
buff[i] = newChar;
}
else
buff[i] = c;
}
return found ? new String(buff) : this;
}
*/
////////////////////////////////////////////////////////////////////////////////////////////////
} // End of Application
Gurpreet Sachdeva
Ranch Hand

Joined: Feb 20, 2001
Posts: 90
Hello Rassaad,
The problem is in this line:
StringBuffer sb = new StringBuffer(br);
Here the class StringBuffer takes a string parameter but you are passing BufferedReader.
Regards
Gurpreet Sachdeva


Regards<BR>Gurpreet Sachdeva<P>For Mock Exams, FAQ, Exam tips and some useful information about Bitshift operator, inner classes, garbage collection,etc please visit: <A HREF="http://www.go4java.lookscool.com" TARGET=_blank rel="nofollow">http://www.go4java.lookscool.com</A>
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Need some basic help with converting
 
Similar Threads
StringTokenizer
sting tokenizer in a loop(vv urgent)
String related query
confused with String Equality
Urgent Need some basic help with converting