首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

: 关于缓冲通道有关问题

2012-02-22 
求助: 关于缓冲通道问题下面的程序要输出一段字符到d盘下面的一个文件夹,输出之后发现字符串之间都有空格,

求助: 关于缓冲通道问题
下面的程序要输出一段字符到d盘下面的一个文件夹,输出之后发现字符串之间都有空格,这是为什么?如何去掉?谢谢


import   java.io.*;
import   java.nio.channels.*;
import   java.nio.*   ;

public   class   for_buffer   {

public   static   void   main(String[]   args)   {
//   TODO   Auto-generated   method   stub
File   afile   =   new   File( "d://java/new.txt ")   ;
FileOutputStream   outputfile   =   null   ;
if(afile.exists()){
try{
outputfile   =   new   FileOutputStream(afile)   ;
}
catch(Exception   e){
System.out.println( "1 ")   ;
}
FileChannel   outputchannel   =   outputfile.getChannel()   ;
ByteBuffer   b1   =   ByteBuffer.allocate(24)   ;
CharBuffer   c1   =   b1.asCharBuffer()   ;
c1.put( "hello ".toCharArray())   ;
try{
outputchannel.write(b1)   ;
}
catch(Exception   e){
System.out.println( "2 ")   ;
}
}
else{
System.out.println( "no   file ")   ;
}
}

}

[解决办法]
比较偏 。。 。
[解决办法]
换 ByteBuffer 试试

热点排行