请各为大虾们指点 本人的这段代码不可以换行输入,请问在IO中用什么函数可以在写的时候换行。 还有,用哪个方法可以不将写好的文件里的内容给从新覆盖public void setFile() throws IOException{
System.out.println("Please write words:");
try {
FileOutputStream os = new FileOutputStream("D:/OutputTest.ini");
int n = 1024, count;
byte bt[] = new byte[n];
count = System.in.read(bt);
os.write(bt,0,count);
os.close();
System.out.println("Save is ok!"); } catch (FileNotFoundException e) {
e.printStackTrace();
}
}
这种方法会把以前输入了的内容覆盖,我不想让它覆盖以前的内容而继续写,也希望能够换行输入,请各位指点。
System.out.println("Please write words:");
try {
FileOutputStream os = new FileOutputStream("D:/OutputTest.ini");
int n = 1024, count;
byte bt[] = new byte[n];
count = System.in.read(bt);
os.write(bt,0,count);
os.close();
System.out.println("Save is ok!"); } catch (FileNotFoundException e) {
e.printStackTrace();
}
}
这种方法会把以前输入了的内容覆盖,我不想让它覆盖以前的内容而继续写,也希望能够换行输入,请各位指点。
解决方案 »
- FTP上传后,文件大小问题
- java和c++里面的方法或者函数加static会怎么样?
- 一道关于JAVA传值的选择题,请朋友们帮我分析一下谢谢了
- 关于Singleton单例模式的一点疑问,高手指点
- 在classpath里只写一个文件夹, 可以包含这个文件夹下所有的jar文件吗?
- javax.swing中JFrame,JDialog,JWindow,JApplet之间的层次关系是什么
- 请抽出点时间来看看!
- 望各位大虾指导!!!
- 小弟想在深圳找份从事JAVA开发的工作,各位前辈帮忙呀!
- 谁知道如何使用sygate作二级代理〉??
- 急,各位高手帮忙解决一下!JTable的问题
- tomcat如何实现双机热备?
import java.io.IOException;
import java.io.RandomAccessFile; public class RandomAccessFileTest {
public RandomAccessFileTest() {
try {
RandomAccessFile dos = new RandomAccessFile("tmp1", "rw");
dos.writeInt(1);
dos.seek(0);
System.out.println(dos.readInt());
} catch (IOException e) {
e.printStackTrace();
}
} public static void main(String xx[]) {
new RandomAccessFileTest();
}
}
public FileOutputStream(File file,
boolean append)
throws FileNotFoundException
append - if true, then bytes will be written to the end of the file rather than the beginning