Hi,
Can someone please help me with the homework? It is only putting the
first character of the first line in my output file.
Here is my ChangeToUpperCase Class:
import java.io.FilterInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.*;
public class ChangeToUpperCaseInputStream extends FilterInputStream{
public ChangeToUpperCaseInputStream(InputStream in) {
super(in);
}
public InputStream StreamToUpper() {
BufferedReader buff = new BufferedReader(new InputStreamReader
(super.in));
StringBuilder str = new StringBuilder();
String line = null;
try {
while((line=buff.readLine())!=null) {
str.append(line.toUpperCase() + "\n");
}
InputStream in2 = new ByteArrayInputStream((str.toString
()).getBytes("UTF-8"));
return in2;
} catch (IOException e) {}
return null;
}
public int read() throws IOException {
int c = StreamToUpper().read();
return c;
}
}
Here is my ChangeToUpperOutput Class:
import java.io.*;
public class ChangeToUpperCaseOutputStream extends FilterOutputStream{
public ChangeToUpperCaseOutputStream(OutputStream out) {
super(out);
}
public void write(int b) throws IOException {
out.write(b);
}
}
Here is the main method:
import java.io.*;
public class MyIOStreamProject {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
ChangeToUpperCaseInputStream in = null;
ChangeToUpperCaseOutputStream out = null;
try {
in = new ChangeToUpperCaseInputStream(new FileInputStream
("farrago.txt"));
out = new ChangeToUpperCaseOutputStream(new
FileOutputStream("outagain.txt"));
} catch (FileNotFoundException e) {
System.err.println("CheckedIOTest: " + e);
System.exit(-1);
} catch (IOException e) {
System.err.println("CheckedIOTest: " + e);
System.exit(-1);
}
int c;
while ((c = in.read())!=-1)
out.write(c);
in.close();
out.close();
}
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---