Probably the problem is in "main". See the following code:
-- Main --
public static void main(String[] args)
{
// TODO code application logic
here
ChangeToUpperCaseInputStream in =
null;
FileOutputStream out =
null;
try
{
in = new
ChangeToUpperCaseInputStream(
new
FileInputStream("farrago.txt"));
out = new
FileOutputStream("outagain.txt");
} catch (FileNotFoundException e)
{
System.err.println("MyIOProject: " +
e);
System.exit(-1);
} catch (IOException e)
{
System.err.println("MyIOProject: " +
e);
System.exit(-1);
}
int
c;
try
{
while ((c = in.read()) != -1)
{
out.write(c);
}
} catch (IOException e)
{
System.err.println("MyIOProject: " +
e);
System.exit(-1);
}
try
{
if (in != null)
{
in.close();
}
if (out != null)
{
out.close();
}
} catch (IOException e)
{
//
Ignore
}
-- ChangeToUpperCaseInputStream --
public class ChangeToUpperCaseInputStream extends FilterInputStream
{
public ChangeToUpperCaseInputStream(InputStream in)
{
super(in);
}
@Override
public int read() throws IOException
{
int result =
super.read();
return (result == -1) ? result :
Character.toUpperCase((char)result);
}
}
On 2/27/10 6:48 PM, bsquare wrote:
> Hi !
> I have some problem with that howework.
> I must finish it before tomorrow and I am getting crazy !
> I've just created the two files (see the code).
> I tried different codes but I still don't get the file in upper case.
> Can anyone help me, please !
> Thanks in advance
>
> import java.io.*;
> /**
> *
> * @author Béatrice
> */
> public class ChangeToUpperCaseInputStream extends FilterInputStream {
>
>
> //Creates a new instance of ChangeToUpperCaseInputStream
> public ChangeToUpperCaseInputStream(InputStream in){
> super(in);
> }
>
> /* 1st try
> public int read() throws IOException {
> int result = super.read();
> return (result == -1)? result : Character.toUpperCase((char)result);
> } */
>
> // 2nd try
> public int read() throws IOException {
> int b = in.read();
> if (b != -1) {
> b= Character.toUpperCase(b);
> }
> return b;
> }
>
> public int read(byte[] b) throws IOException {
> int len;
> len = in.read(b, 0, b.length);
> if (len != -1) {
> for (int i=0; i<len; i++)
> b[i]= (byte) Character.toUpperCase (b[i]);
> }
> return len;
> }
>
> public int read(byte[] b, int off, int len) throws IOException {
> len = in.read(b, off, len);
> if (len != -1) {
> for (int i=off; i<(off+len); i++)
> b[i]= (byte) Character.toUpperCase (b[i]);
> }
> return len;
> }
> }
>
>
--
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
