• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need some basic help with converting

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
Regards
Gurpreet Sachdeva
 
reply
    Bookmark Topic Watch Topic
  • New Topic