I want this programme to write numbers in my txt file but instead of that it writes some strange signs.Does anyone can fix it and make it write numbers from the array
package int1;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.nio.channels.FileChannel;
public class broj_u_skl {
public static void main(String[] args) {
File a = new File("C:\\Users\\Jovan\\Desktop");
File b = new File(a,"Pisem.txt");
try {
b.createNewFile();
}catch(Exception e) {
}
FileOutputStream st = null;
try {
st = new FileOutputStream(b);
}catch(Exception e) {
}
this is that array:
int[] c = {1,2,3,4,5,6,7,8,9};
but it doesnt write this numbers above.
ByteBuffer bff = ByteBuffer.allocate(100);
FileChannel ch = st.getChannel();
IntBuffer ib = bff.asIntBuffer();
for (int i = 0; i < c.length; i++) {
ib.put(c[i]);
}
bff.position(4*ib.position());
bff.flip();
try {
ch.write(bff);
}catch(IOException e) {
}
}
}