How to read in as a byte instead of String

edited April 2016 in Arduino

` import processing.serial.*; import*; Serial myPort; int mySwitch; String transmitter[] = new String[1280000]; //initialize array

void setup(){ 
         //Open the serial port for communication with the Arduino 
         //Make sure the COM port is correct 
         myPort = new Serial(this, "COM6", 9600); 

void draw() { 
        if(mySwitch == 1)
           int index = 0; 
           while(index < 128000) 
             if(index%128 == 0)

         mySwitch = 0; 

void readData(String myFileName){ 

         File file=new File(myFileName); 
         BufferedReader br=null; 

           br=new BufferedReader(new FileReader(file)); 

           String transmit=null; 
           int i = 0; 
           /* keep reading each line until you get to the end of the file */ 
                while((transmit = br.readLine()) != null) 
                   transmitter[i++] = transmit; 

         }catch(FileNotFoundException e){ e.printStackTrace(); } 

         catch(IOException e){ e.printStackTrace(); } 

                 try { 
                   if (br != null) br.close();  
                 catch (IOException e) { e.printStackTrace(); } 
} `

In the above code, I have an String array and I'm reading lines from a file and saving them as strings. How would I save them as byte/char inside an array of byte/char?

Basically, I have a file of integers on each line, each integer in the range [0, 255]. And I want to read this integer and send it to the Arduino. The Arduino function reads a byte at a time. This is the issue I am trying to solve.



Sign In or Register to comment.