Java RandomAccessFile дÈëtxtÎļþ - Java / Java SE
ÓÃRandomAccessFileдÈëTXTÎļþ²é¿´Ê±ÊÇÂÒÂ룬ÇëÎÊÓÐʲô·½·¨¿ÉÒÔд³É¿É¶ÁµÄÎļþ£¬²»ÊÇÓÃÆäËûµÄÎļþ²Ù×÷£¬¾ÍÊÇÖ»ÓÃRandomAccessFileµÄ·½·¨ÊÇ·ñ¿ÉÒÔʵÏÖ£¿
Java code:
import java.io.*;
public class RandomAccessFileDemo
{
public static void main(String[] args) throws IOException
{
RandomAccessFile raf=new RandomAccessFile("random.txt","rw");
raf.writeBoolean(true);
raf.writeInt(2008);
raf.writeChar('Äê');
raf.writeDouble(08.08);
raf.writeUTF("Å·ÁÖÆ¥¿ËÔ˶¯»á");
raf.seek(1);
System.out.println(raf.readInt());
System.out.println(raf.readChar());
System.out.println(raf.readDouble());
System.out.println(raf.readUTF());
raf.seek(0);
System.out.println(raf.readBoolean());
raf.close();
}
}
ÕâÖÖÂÒÂëÒ»°ã¶¼ÊÇÒòΪ×Ö·û´®µÄ±àÂë»òÕß×Ö·û´®×ª»»×Ö½ÚµÄʱºò±àÂ벻ͬ¶øÒýÆðµÄ¡£ËùÒÔÊ×ÏÈ×îºÃ¶ÔҪдÈëÎļþµÄ×Ö·û´®»òÕßÁ÷¶¼½øÐÐÒ»±é±àÂëÉ趨¡£
1¡¢String.getBytes£¨£©½«»á°´ÕÕµ±Ç°ÏµÍ³Ä¬ÈϵÄencoding·½Ê½»ñµÃ×Ö·û´®µÄ Bytes£¬RandomAccessFile.write(byte[])½«Õâ¸öbyteÊý×éÕýȷдÈë¡£ÓÉÓÚдÈëµÄʵ¼Ê¾ÍÊÇWindowsƽ̨µÄ nativecode±àÂ룬ËùÒÔÎļþ»¹Äܹ»±»ÕýÈ·µÄÔĶÁ¡£
2¡¢RandomAccessFile.writeBytes(String)½«×Ö·û´®µÄ¸÷¸ö×Ö·û£¨µ±È»ÊÇÓÃunicode±àÂëµÄ£©µÄ¸ß8λȥµô£¬Ð´ÈëÎļþ¡£
3¡¢RandomAccessFile.writeChars(String)½«×Ö·û´®µÄ¸÷¸ö
Ïà¹ØÎÊ´ð£º
ÎÒÔÚjspÒ³Ãæ´æÉÏÒ»¸ösession,±¾Ò³Ã滹¿ÉÒÔÈ¡³öÖµÀ´.
µ«ÊÇһˢÐÂ,»òÕß´ò¿ªÐµÄÒ³Ãæ¾ÍÈ¡²»³öÖµÀ´ÁË.
Ææ¹ÖµÄÊÇ,ÎÒ²âÊÔÁíÒ»¸ö³ÌÐòʱºò
ÔÚjspÒ³Ãæ´æÉÏÒ»¸ösession,±¾Ò³Ãæ¿ÉÒÔÈ¡³öÖµÀ´,ˢлò´ò¿ªÐÂÒ³ÃæÖµÄÜÈ¡³öÀ´ÁË.
......
ÎÒÏÖÔÚÏëÓÃsshÕûºÏÀ´×öÒ»¸öÂÛ̳£¬µ«Êý¾Ý¿â·½Ãæ²»ÐУ¬ÎÒÖ÷Òª²»»áÉæ¼°Êý¾Ý¿â£¬²»ÖªµÀ·¢Ìû±í£¬ºÍ»ØÌû±íÒªÈçºÎÉè¼ÆºÍÇø·Ö¡£²»ÖªµÀËÓÐÒ»¸ö¼òµ¥µÄ˼·£¬À´Éè¼ÆÕâЩ±í¡£Ð»Ð»ÁË¡£
·¢ÌûºÍ»ØÌûÓÃͬһÕÅ±í ¡£·¢Ìû id user ......
<%@page language="java" contentType="text/html;charset=gb2312" import="java.sql.*"%>
<jsp:useBean id="db" class="wang.connectDB"/>
< ......
²àÖØÓÚ»¥ÁªÍø¿ª·¢
JAVA¿ª·¢¹¤³Ìʦ
ְλÃèÊö£º
1¡¢°´USECASE½øÐÐÒµÎñÐèÇó·ÖÎöºÍÈí¼þ¸ÅÒªÉè¼Æ£»
2¡¢½øÐÐÈí¼þÏêϸÉè¼ÆºÍ±àÂëʵÏÖ£¬È·±£ÐÔÄÜ¡¢ÖÊÁ¿ºÍ°²È«£»
3¡¢Î¬»¤ºÍÉý¼¶ÏÖÓÐÈí¼þ²úÆ·£¬¿ìËÙ¶¨Î»² ......
ÎÒÃÇÓÐÏîÄ¿Ïë×齨һ¸ö¿ª·¢ÍŶӣ¬
Ö÷ÒªÓà tomcat,java,struts2,ÎÒÃǵĺËÐijÉÔ±¶¼ÊǾÑé·Ç³£·á¸»µÄϵͳÉè¼Æʦ£¬
Èç¹ûÄúÔÚÌì½ò£¬Í¬Ê±¶Ôjava±È½Ï¸ÐÐËȤ£¬
¿ÉÒÔ¼ÓÈëÎÒÃÇ¡£
Ï£ÍûÒªÇó
1¡£°®ºÃ±à³Ì
......