i want to write something with this code but after i run there are white spaces between characters. but in code i dont give space to string.
import java.io.*;
public class WriteText{
public static void main(String[] args) {
FileOutputStream fos;
DataOutputStream dos;
try {
File file= new File("C:\\JavaWorks\\gui\\bin\\hakki\\out.txt");
fos = new FileOutputStream(file);
dos=new DataOutputStream(fos);
dos.writeChars("Hello World!");
}
catch (IOException e) {
e.printStackTrace();
}
}
}
Output is (in text file) : H e l l o W o r l d !
Use writeBytes
Essentially, writeChars will write every character as 2 bytes. The second one you are seeing as extra spaces.