im having some trouble with this code the document im trying to reverse the text in is about 1000 pages in MS Word and when i use it the whole document doesnt get reversed it does so much then cuts off the rest
anyone see why it would do that? the program works it just cuts off a lot of the document.
import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.io.InputStreamReader; import java.io.RandomAccessFile; import java.io.Reader; import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; public class Test { public static void main(String... args) throws Exception { // Stub input. You need to gather it yourself from your sources. File file = new File("C:/Documents and Settings/jerky/Desktop/Item.doc"); long length = file.length(); // Get it from HTTP request header using file upload API in question (Commons FileUpload?). String encoding = "UTF-8"; // Get it from HTTP request header using file upload API in question (Commons FileUpload?). InputStream content = new FileInputStream(file); // Get it from HTTP request body using file upload API in question (Commons FileUpload?). // Now the real job. Reader input = new InputStreamReader(content, encoding); RandomAccessFile output = new RandomAccessFile(new File("C:/Documents and Settings/jerky/Desktop/Item5.doc"), "rwd"); CharsetEncoder encoder = Charset.forName(encoding).newEncoder(); for (int data; (data = input.read()) != -1;) { ByteBuffer bytes = encoder.encode(CharBuffer.wrap(new char[] { (char) data })); length -= bytes.limit(); output.seek(length); output.write(bytes.array()); } // Should actually be done in finally. input.close(); output.close(); } }