import java.io.*;public class task_99_2 {
public static void main(String args[]) throws IOException{
String s;
RandomAccessFile rf=new RandomAccessFile("e:/Test1.txt","rw");
RandomAccessFile raf=new RandomAccessFile("e:/Test2.txt","rw");
rf.seek(rf.length());
raf.seek(0);
while((s=raf.readLine())!=null){
rf.writeUTF(s);
System.out.println(s); }
rf.close();
raf.close();
}
}
public static void main(String args[]) throws IOException{
String s;
RandomAccessFile rf=new RandomAccessFile("e:/Test1.txt","rw");
RandomAccessFile raf=new RandomAccessFile("e:/Test2.txt","rw");
rf.seek(rf.length());
raf.seek(0);
while((s=raf.readLine())!=null){
rf.writeUTF(s);
System.out.println(s); }
rf.close();
raf.close();
}
}
解决方案 »
- 这个。。不用Class.forName加载类怎么也连上数据库了??
- 关于ToolTip
- 有创业想法的朋友来这里QQ群:10496416(创业中国)
- 我想做一个曲线走势图,就是读取数据库,然后画一个走势图出来,请问界面和曲线如何画?
- 有谁能否将XP下的JDK1.4环境配置贴一下??
- TYPE_SCROLL_INSENSITIVE 和 TYPE_SCROLL_SENSITIVE 有何区别?
- 简单问题求救!用JBuilder9打包exe文件时遇到的问题,详细请进!
- 一个界面问题,快来拿分
- 小弟欲用java applet编制一套网上学代会环境
- 如何判断一个对象是否在一定时间内一直在一个队列中而没有被取走过?
- opennms怎么配置
- 插入了数据,却看不见!
例如写出去 9个, 就是 [0, 9]
写出去 300个, 就是 [1, 44]
就因为有了这两个byte,所以才有了你看到的方块啊,空白啊之类的PS:writeUTF并不输出回车换行之类的[code=HTML]writeUTF
public final void writeUTF(String str)
throws IOExceptionWrites a string to the file using modified UTF-8 encoding in a machine-independent manner.
First, two bytes are written to the file, starting at the current file pointer, as if by the writeShort method giving the number of bytes to follow. This value is the number of bytes actually written out, not the length of the string. Following the length, each character of the string is output, in sequence, using the modified UTF-8 encoding for each character.
Specified by:
writeUTF in interface DataOutput
Parameters:
str - a string to be written.
Throws:
IOException - if an I/O error occurs.[code]
首先,你用readline来读,读进来的s里面是不含换行符的
你又用writeUTF来写s入文件,本身又不写换行符
所以这个问题,跟换行符根本没关系
就是上面那个两个byte的问题
{
public static void main(String args[]) throws IOException
{ String s;
//RandomAccessFile rf=new RandomAccessFile("Test2.txt","rw");
//RandomAccessFile raf=new RandomAccessFile("Test1.txt","rw");
BufferedReader raf=new BufferedReader(new FileReader("Test1.txt"));
OutputStreamWriter rf=new OutputStreamWriter(new FileOutputStream("Test2.txt"),"gb2312");
//rf.seek(rf.length());
//raf.seek(0);
while((s=raf.readLine())!=null)
{
//s=new String (s.getBytes("UTF-8"),"UTF-8");
//rf.writeChars(s);
rf.write(s);
System.out.println(s); }
rf.close();
raf.close();
}
}
发现 Text1和Text2
必须都是utf-8编码时才会出现lz说的情况!!
如果是3#说的情况的话 不应该这样吧!!!