Results 1 to 3 of 3
  1. #1
    Darkzombies is offline Senior Member
    Join Date
    Nov 2012
    Posts
    105
    Rep Power
    0

    Default Really weird text writing O_o

    Java 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

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Really weird text writing O_o

    Quote Originally Posted by Darkzombies View Post
    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.

  3. #3
    Darkzombies is offline Senior Member
    Join Date
    Nov 2012
    Posts
    105
    Rep Power
    0

    Default Re: Really weird text writing O_o

    So just change char to int? Simple, it slipped right past me xD, thanks
    Last edited by Darkzombies; 11-22-2012 at 02:46 AM.

Similar Threads

  1. BlueJ help! weird error text meesed up
    By linux1man in forum Other IDEs
    Replies: 6
    Last Post: 02-07-2013, 04:54 PM
  2. Replies: 8
    Last Post: 07-17-2011, 03:38 PM
  3. Writing Text To A File
    By loopsnhoops in forum New To Java
    Replies: 15
    Last Post: 06-01-2011, 04:27 AM
  4. Replies: 1
    Last Post: 02-27-2010, 02:29 AM
  5. writing text to file
    By notwist in forum New To Java
    Replies: 3
    Last Post: 04-25-2008, 05:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •