public void writeToFile(String
dataFile, String fileName) {
File file = new File(fileName);
try {
if (!file.exists()) {
file.createNewFile();
}
byte[] dataFileBytes = dataFile.getBytes(Charset.forName("UTF-16"));
FileChannel out = new FileOutputStream(fileName).getChannel();
ByteBuffer buff = ByteBuffer.allocateDirect(dataFileBytes.length);
File file = new File(fileName);
try {
if (!file.exists()) {
file.createNewFile();
}
byte[] dataFileBytes = dataFile.getBytes(Charset.forName("UTF-16"));
FileChannel out = new FileOutputStream(fileName).getChannel();
ByteBuffer buff = ByteBuffer.allocateDirect(dataFileBytes.length);
for
(int i = 0; i < dataFileBytes.length; i++)
buff.put(dataFileBytes[i]);
buff.flip();
out.write(buff);
buff.clear();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
buff.put(dataFileBytes[i]);
buff.flip();
out.write(buff);
buff.clear();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
No comments:
Post a Comment