A photo of your code isn't an acceptable (or useful) way of showing your code. Please cut and paste the code into your post (and wrap it in code tags ) so we can easily read the code and best advise on how to get it to do what you require.
Well, the newline character is represented by "\n" in Java, not by "/n". But you've got another problem after that one, don't you? The way you quote the requirements, they don't explicitly say that all of the other characters should be copied unchanged from the input to the output. So maybe that isn't a requirement?
posted 2 years ago
Sorry that was my typing mistake but its not working
That's not the proper way to read a file, and the error is in the handling of b. First of all, you check if it's -1 after you've written it to the output stream. Secondly, InputStream.read() returns an int value from -1 to 255 (inclusive). Everything but -1 indicates a valid byte. However, if you cast it to a byte, its range is changed to -128 to 127 (inclusive). -1 is in there twice -- once as -1 cast to byte, and once as 255 cast to byte. That's why the method returns an int and not a byte.
Here's how you should properly read a file:
Or a bit shorter:
I'd also like to advise you to:
1) Use a Reader instead of an InputStream. Your code will only properly handle ASCII files.
2) Use a BufferedReader (or BufferedInputStream) to improve performance.
3) Close your streams when you're done with them (in a try-finally construct, or preferably try-with-resources).