This reference is for Processing 3.0+. If you have a previous version, use the reference included with your software in the Help menu. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Core Javadoc and Libraries Javadoc.

Name

loadBytes()

Examples
// Open a file and read its binary data 
byte b[] = loadBytes("something.dat"); 
 
// Print each value, from 0 to 255 
for (int i = 0; i < b.length; i++) { 
  // Every tenth number, start a new line 
  if ((i % 10) == 0) { 
    println(); 
  } 
  // bytes are from -128 to 127, this converts to 0 to 255 
  int a = b[i] & 0xff; 
  print(a + " "); 
} 
// Print a blank line at the end 
println(); 
Description Reads the contents of a file and places it in a byte array. If the name of the file is used as the parameter, as in the above example, the file must be loaded in the sketch's "data" directory/folder.

Alternatively, the file maybe be loaded from anywhere on the local computer using an absolute path (something that starts with / on Unix and Linux, or a drive letter on Windows), or the filename parameter can be a URL for a file found on a network.

If the file is not available or an error occurs, null will be returned and an error message will be printed to the console. The error message does not halt the program, however the null value may cause a NullPointerException if your code does not check whether the value returned is null.
Syntax
loadBytes(filename)
Parameters
filename String: name of a file in the data folder or a URL.
Returnsbyte[]
RelatedloadStrings()
saveStrings()
saveBytes()
Updated on August 17, 2018 03:36:31pm EDT

Creative Commons License