File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Need some basic help with converting


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

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);
br = new String(sb);
/* App4.replace(a,aa); //Maybe by modifying this function it might work */
//Verify output
int temp;

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

//out.write(" " + st.nextToken());
System.out.print(" " + st.nextToken());
} else {
System.out.println(" ");
} //for
} //while

} //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;
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.
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="" TARGET=_blank rel="nofollow"></A>
I agree. Here's the link:
subject: Need some basic help with converting
It's not a secret anymore!