Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Need some basic help with converting  RSS feed

Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!