-
Write to file
i use below code to write a character to a file, the old contents cleared but nothing is written :
File edgesFile = new File(netFile);
FileOutputStream inFile = null;
try
{
inFile = new FileOutputStream(edgesFile);
}
catch(FileNotFoundException e)
{
e.printStackTrace(System.err);
System.exit(1);
}
FileChannel inChannel = inFile.getChannel();
ByteBuffer buf = ByteBuffer.allocate(48);
buf.putChar('q');
try
{
inChannel.write(buf);
inChannel.force(true);
inChannel.close();
}
catch(IOException e)
{
e.printStackTrace(System.err);
}
and another thing how can i write a string array to a file that any element be in one line?
-
It depends on how you will save them in a file....
You may try to use Formatter for saving files in format, and also the FileWriter....
Those classes are safe to implement.
Code:
void WriteFile throws Exception(){
FileWriter fw = new FileWriter(netFile);
fw.append('q');
fw.close();
}
Code:
void WriteFile throws Exception(){
Formatter write = new Formatter(netFile);
write.format("%c",'q');
write.close();
}
try to test it,