Results 1 to 2 of 2
Thread: Write to file
- 05-21-2008, 12:57 PM #1
Member
- Join Date
- May 2008
- Posts
- 2
- Rep Power
- 0
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?
- 05-21-2008, 01:13 PM #2
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.
Java Code:void WriteFile throws Exception(){ FileWriter fw = new FileWriter(netFile); fw.append('q'); fw.close(); }try to test it,Java Code:void WriteFile throws Exception(){ Formatter write = new Formatter(netFile); write.format("%c",'q'); write.close(); }Last edited by sukatoa; 05-21-2008 at 07:09 PM. Reason: Scanner changed to Formatter....
freedom exists in the world of ideas
Similar Threads
-
how to write onto a file
By mirage_87 in forum New To JavaReplies: 6Last Post: 09-08-2009, 03:54 PM -
how do i write to a text file from an arraylist?
By otoro_java in forum New To JavaReplies: 3Last Post: 01-30-2008, 06:53 AM -
File Write Error
By vikain in forum Advanced JavaReplies: 5Last Post: 01-02-2008, 04:38 AM -
Write unicode into file
By vata2999 in forum New To JavaReplies: 1Last Post: 08-08-2007, 03:04 PM -
Help with write file in java
By mathias in forum New To JavaReplies: 1Last Post: 07-31-2007, 06:51 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks