Skip to content

Commit 29d891f

Browse files
committed
FileUtils: add method to write data to a file
1 parent cb160fd commit 29d891f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/main/java/org/scijava/util/FileUtils.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.io.DataInputStream;
3838
import java.io.File;
3939
import java.io.FileInputStream;
40+
import java.io.FileOutputStream;
4041
import java.io.FilenameFilter;
4142
import java.io.IOException;
4243
import java.net.JarURLConnection;
@@ -151,6 +152,24 @@ public static byte[] readFile(final File file) throws IOException {
151152
return bytes;
152153
}
153154

155+
/**
156+
* Writes the given byte array to the specified file.
157+
*
158+
* @see DigestUtils#bytes(String) To convert a string to a byte array.
159+
* @throws IOException If the file cannot be written.
160+
*/
161+
public static void writeFile(final File file, final byte[] bytes)
162+
throws IOException
163+
{
164+
final FileOutputStream out = new FileOutputStream(file);
165+
try {
166+
out.write(bytes);
167+
}
168+
finally {
169+
out.close();
170+
}
171+
}
172+
154173
/**
155174
* A regular expression to match filenames containing version information.
156175
* <p>

0 commit comments

Comments
 (0)