File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need some basic help with converting

 
Rassaad
Greenhorn
Posts: 3
  • 0
  • 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 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
Posts: 90
  • 0
  • 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.
Regards
Gurpreet Sachdeva
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic