package test;
import java.io.*;
import java.nio.charset.Charset;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
public class MyIO
{
/**
* @param args
*/
public static void main(String[] args) throws Exception
{
/* File f=new File("1.txt");
f.createNewFile();
Thread.sleep(1000);
f.delete();
File f2=new File("dir");
f2.mkdir();
f2.deleteOnExit();
Thread.sleep(3000);*/
/* for(int i=0;i<5;i++)
{
File f=File.createTempFile("xiaowen",".temp");
f.deleteOnExit();
}
Thread.sleep(3000);*/
/* File f=new File("./src");
String [] files=f.list(new FilenameFilter()
{
@Override
public boolean accept(File dir, String name)
{
return name.endsWith(".java");
}
}
);
for(String file:files)
{
System.out.println(file);
}*/
/* System.out.println("input:");
int data;
while((data=System.in.read())!=-1)
{
System.out.write(data);
}*/
/* FileOutputStream fos=new FileOutputStream("/1.txt");
fos.write("www.baidu.com".getBytes());
fos.close();*/
/* FileInputStream fin=new FileInputStream("/1.txt");
byte []buf=new byte[100];
int len=fin.read(buf);
System.out.println(new String(buf,0,len));
fin.close();*/
/* FileOutputStream fos=new FileOutputStream("/1.txt");
BufferedOutputStream bos=new BufferedOutputStream(fos);
bos.write("why is you!!!!".getBytes());
bos.flush();
fos.close();
// bos.close();*/
/* FileInputStream fi=new FileInputStream("/1.txt");
BufferedInputStream bis=new BufferedInputStream(fi);
byte [] b=new byte[100];
int len=bis.read(b);
bis.close();
System.out.println(new String(b,0,len));*/
/* FileOutputStream fo=new FileOutputStream("/1.txt");
BufferedOutputStream bos=new BufferedOutputStream(fo);
DataOutputStream ds=new DataOutputStream(bos);
byte b=3;
int x=11;
char ch='a';
float f=1.5f;
ds.writeByte(b);
ds.writeInt(x);
ds.writeChar(ch);
ds.writeFloat(f);
ds.close();
FileInputStream fi=new FileInputStream("/1.txt");
BufferedInputStream fis=new BufferedInputStream(fi);
DataInputStream di=new DataInputStream(fi);
byte bb=0;
int xx=0;
char chch=0;
float ff=0;
bb=di.readByte();
xx=di.readInt();
chch=di.readChar();
ff=di.readFloat();
System.out.println(bb);
System.out.println(xx);
System.out.println(chch);
System.out.println(ff);
*/
/* FileOutputStream fos=new FileOutputStream("/1.txt");
OutputStreamWriter osw=new OutputStreamWriter(fos);
BufferedWriter bw=new BufferedWriter(osw);
bw.write("http//www.baidu.com");
bw.close();
FileInputStream fis=new FileInputStream ("/1.txt");
InputStreamReader isr=new InputStreamReader(fis);
BufferedReader br=new BufferedReader (isr);
System.out.println(br.readLine());
br.close();*/
/* InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader bis=new BufferedReader(isr);
String str;
System.out.println("input:");
while((str=bis.readLine())!=null)
{
System.out.println(str);
}
bis.close();*/
/* Map m=Charset.availableCharsets();
Set names=m.keySet();
Iterator it=names.iterator();
while(it.hasNext())
{
System.out.println(it.next());
}*/
/* Properties pps=System.getProperties();
// pps.list(System.out);
pps.put("file.encoding", "ISO-8859-1");
// pps.list(System.out);
int data;
byte []buf=new byte [100];
int i=0;
System.out.println("input:");
while((data=System.in.read())!='q')
{
buf[i]=(byte) data;
i++;
}
buf[i]='\0';
String str=new String(buf);
System.out.println(str);*/
/*Map m=Charset.availableCharsets();
Set names=m.keySet();
Iterator it=names.iterator();
while(it.hasNext())
{
System.out.println(it.next());
}*/
/* Properties pps=System.getProperties();
pps.put("file.encoding","ISO-8859-1");
int data;
byte[] buf=new byte[100];
int i=0;
System.out.println("INPUT:");
while((data=System.in.read())!='q')
{
buf[i]=(byte)data;
i++;
}
pps.list(System.out);
String str=new String(buf,0,i);
//System.out.println(str);
String strGBK=new String(str.getBytes("ISO-8859-1"),"GBK");
System.out.println(str);
System.out.println(strGBK);*/
/* RandomAccessFile raf=new RandomAccessFile("/1.txt","rw");
int x=5;
String name="xflksd";
raf.writeInt(x);
raf.writeUTF(name);
x++;
raf.writeInt(x);
raf.writeUTF(name);
raf.seek(0);
System.out.println(raf.readInt());
System.out.println(raf.readUTF());
System.out.println(raf.readInt());
System.out.println(raf.readUTF());
System.out.println("LENGTH:"+raf.length());*/
}
}
package test;
import java.io.*;
public class MIO
{
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception
{
// TODO Auto-generated method stub
Student st1=new Student(20,"小米",30);
Student st2=new Student(21,"小华",25);
FileOutputStream fos=new FileOutputStream("/1.txt");
ObjectOutputStream oos=new ObjectOutputStream(fos);
oos.writeObject(st1);
oos.writeObject(st2);
oos.close();
FileInputStream fis=new FileInputStream("/1.txt");
ObjectInputStream ois=new ObjectInputStream(fis);
Student st;
st=(Student)ois.readObject();
st.display();
st=(Student)ois.readObject();
st.display();
ois.close();
}
}
package test;
import java.io.IOException;
import java.io.Serializable;
public class Student implements Serializable
{
private int age;
private String name;
transient private int num;
public Student(int age,String name,int num)
{
this.age=age;
this.name=name;
this.num=num;
}
public void display()
{
System.out.println("age:"+age+"\t"+"name:"+name+"\tnum:"+num);
}
/* private void writeObject(java.io.ObjectOutputStream out)
{
try
{
out.writeInt(age);
out.writeUTF(name);
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void readObject(java.io.ObjectInputStream in) throws IOException
{
age=in.readInt();
name=in.readUTF();
}*/
}