关于中文的问题,以前这上面有类似的帖子,看看就知道了,应该作些转换才好。
用文本文件好像很难实现同时的访问吧,在文件Open的状态,再进行Open操作有问题
用文本文件好像很难实现同时的访问吧,在文件Open的状态,再进行Open操作有问题
解决方案 »
- java oop
- 请教日期格式字符串如何进行大小比较? 实例见内容!
- JPA OneToMany 映射问题
- Oracle与SSH框架集成spring配置文件怎么写?
- 循环赋值的问题
- JFileChooser怎样默认文件名?
- spring+hibernate在SPRING配置文件中报错,求解
- jsdk里有没有将int数高低位交换的函数?
- 高手赐教: Java线程中yield()和修饰符volatile
- 有谁知道JCREATOR里为什么在编译applet文件时,能编译通过,可一运行就提示:没有main函数呀!
- 请教:使用java.net中httpURLConnection类模拟post方法?、、全部分数送上!
- 窗口中相互调用问题,请大家帮忙。
import java.io.*;
class a1915
{
public static void main(String args[])
throws IOException
{
RandomAccessFile raf=new RandomAccessFile("a1915.dat","rw");
DataInputStream dis=new DataInputStream(System.in);
String name=null,password=null;
int sex,height,i,j;
int reclen=16,namelen=8,passwordlen=8;
long n=raf.length()/reclen;
while(true)
{
System.out.print("Key in your username:");
System.out.flush();
name=dis.readLine();
if(name.length()==0) break;
System.out.print(" password:");
System.out.flush();
password=dis.readLine();
raf.seek(n*reclen);
n++;
//***********name input
if(name.length()>=namelen)
{
for (j=0;j<namelen;j++)
raf.writeByte((int)name.charAt(j));
}
else
{
for(j=0;j<name.length();j++)
raf.writeByte((int)name.charAt(j));
for(j=name.length();j<namelen;j++)
raf.writeByte(0x20);
}
//**********password input
if(password.length()>=passwordlen)
{
for (j=0;j<passwordlen;j++)
raf.writeByte((int)password.charAt(j));
}
else
{
for(j=0;j<password.length();j++)
raf.writeByte((int)password.charAt(j));
for(j=password.length();j<passwordlen;j++)
raf.writeByte(0x20);
}
}//while
raf.close();
}//public
}//class
import java.io.*;
class a1916
{
public static void main(String args[])
throws IOException
{
RandomAccessFile raf=new RandomAccessFile("a1915.dat","rw");
DataInputStream dis=new DataInputStream(System.in);
String name=null,password=null,s;
byte _name[]=new byte[8],_password[]=new byte[8];
int i,j;
int reclen=16,namelen=8,passwordlen=8;
long p,n=raf.length();
while(true)
{
System.out.print("\nkey in record number:");
System.out.flush();
s=dis.readLine();
if(s.length()==0) break;
p=Long.parseLong(s,10);
if(p*reclen>n-1)
{
System.out.println("out of range!");
System.exit(0);
}
raf.seek(p*reclen);
StringBuffer nacode= new StringBuffer("");
StringBuffer pwcode= new StringBuffer("");
for(j=0;j<namelen;j++)
{_name[j]=raf.readByte();nacode.append((char)_name[j]);}
for(j=0;j<passwordlen;j++)
{_password[j]=raf.readByte();pwcode.append((char)_name[j]);}
name=nacode.toString();
password=pwcode.toString();
System.out.print("name="+name);
password=pwcode.toString();
System.out.print("password:"+password);
System.out.flush();
}
raf.close();
}
}
怎么解决中文问题?
谢谢!