Really weird text writing O_o
Code:
import java.io.*;
public class Test{
public static void main(String args[]){
try{
byte bWrite [] = {11,21,3,40,5};
OutputStream os = new FileOutputStream("C:/Users/Darkzombies/Desktop/JavaStuff/test.txt");
for(int x=0; x < bWrite.length ; x++){
os.write( bWrite[x] ); // writes the bytes
}
os.close();
InputStream is = new FileInputStream("C:/Users/Darkzombies/Desktop/JavaStuff/test.txt");
int size = is.available();
for(int i=0; i< size; i++){
System.out.print((char)is.read() + " ");
}
is.close();
}catch(IOException e){
System.out.print("Exception");
}
}
}
ends up writing a bunch of random symbols I've never seen before instead of the numbers, and the output is just a bunch of question marks, I have no idea what happened or how to fix it. O_o
Re: Really weird text writing O_o
Quote:
Originally Posted by
Darkzombies
instead of the numbers
If you are expecting it to write 11 21 3 40 and 5 to the file then that is not correct. What you are doing is writing the character that corresponds to those values and not the values themselves.
Re: Really weird text writing O_o
So just change char to int? Simple, it slipped right past me xD, thanks