java 文件的读写,追加
写入读出
String num = request.getParameter("num");
String sessionId = request.getParameter("s") + ";" + num + "\n";
File writefile;
try{
String path = "tt.txt";
writefile = new File(path);
if (writefile.exists() == false) {
writefile.createNewFile();
writefile = new File(path); // 重新实例化
}
FileOutputStream fos = new FileOutputStream(writefile);
out.println("###content:" + sessionId);
fos.write(sessionId.getBytes());
fos.flush();
fos.close();
byte[] b = new byte[17*1024];
FileInputStream fis = new FileInputStream(writefile);
fis.read(b);
String s = new String(b);
out.println(s);
fis.close();
}catch(Exception ex){
System.out.println(ex.getMessage());
}
追加:
String path=request.getRealPath(".");
RandomAccessFile rf=new RandomAccessFile("WriteData.txt","rw");//定义一个类RandomAccessFile的对象,并实例化
rf.seek(rf.length());//将指针移动到文件末尾
rf.writeBytes("\nAppend a line to the file!");
rf.close();//关闭文件流
out.println("写入文件内容为:<br>");
FileReader fr=new FileReader(path + "\\WriteData.txt");
BufferedReader br=new BufferedReader(fr);//读取文件的BufferedRead对象
String Line=br.readLine();
while(Line!=null){
out.println(Line + "<br>");
Line=br.readLine();
}
fr.close();//关闭文件
相关文档:
谈谈回调吧,以前学java的时候居然没接触到这个词汇,汗,最近研究hibernate和spring结合时,发现spring实现hibernate时应用了回调机制,于是google了很多次,终于有所体会了,现在做下小小的总结,以便加深印象!
java回调机制:
软件模块之间总是存在着一定的接口,从调用方式上,可以把他们分为三 ......
《java语言程序设计(一)》2009年自学考试大纲第2章
www.wesiedu.com 2009-5-5 在线模拟考场
第2章 运算和语句
(一)课程内容
2.1 数据运算
2.1.1 赋值运算
2.1.2算术运算
2.1.3自增和自减运算
2.1.4关系运算
2.1.5逻辑运算
2.1.6条件运算
2.1.7其他运算
2.2语句
2.2.1基本语句
2.2 ......
《java语言程序设计(一)》2009年自学考试大纲第3章
www.wesiedu.com 2009-5-5 在线模拟考场
第3章 面向对象编程基础
(一)课程内容
3.1 面向对象的基本概念
3.2 Java的类和对象
3.2.1 类
3.2.2对象
3.2.3实例变量和类变量
3.2.4实例方法和类方法
3.2.5访问权限
3.2.6继承
3.2.7 Java ......
第5章图形界面设计(一)
(一)课程内容
5.1 图形界面设计基础
5.1.1 AWI’和Swing
5.1.2组件和容器
5.1.3事件驱动程序设计基础
5.2框架窗口 .
5.3标签、按钮和按钮事件
5.3.1 标签
5.3.2按钮和按钮事件处理
5.4面板
5.4.1 JPanel
5.4.2 JScrollPane
5.5布局设计
5.5.1 FlowI.ayout布局
5.5.2 BorderI.a ......
/*
本段代码在公司项目中实际远程调用第三方公司提供的C#开发WebService的示例
*/
/**
* 登录游戏
*
* @param paramPN
* @param paramTerraceID
* @param paramSvrID
*/
private String loginGame(String paramPN, HttpServletRequest req){
&n ......