WEB开发网
开发学院WEB开发Jsp java的io简单应用 选择自 FrankTaylor 的 Blog 阅读

java的io简单应用 选择自 FrankTaylor 的 Blog

 2008-01-05 09:08:20 来源:WEB开发网   
核心提示://从文件里读数据,显示到屏幕上package com.yourcompany.core; import java.io.*;public class Think { public static void main(String[] args) { try { FileInputStream file

  //从文件里读数据,显示到屏幕上
package com.yourcompany.core;
import java.io.*;

public class Think {

public static void main(String[] args) {

try {

FileInputStream file = new FileInputStream("d:\\sss.txt");
char[] c = new char[file.available()];
for (int i = 0 ; i<c.length;i++) {
c[i] = (char)file.read();

}
System.out.PRint(c);

}
catch(FileNotFoundException e) {

e.printStackTrace();
}
catch(IOException e) {

e.printStackTrace();
}

}
}
//在屏幕上写东西到文件中
package com.yourcompany.core;

import java.io.*;
import java.util.*;


public class Think {

public static void main(String[] args) {

try {

byte[] c = new byte[1000] ;
System.in.read(c);
FileOutputStream file = new FileOutputStream("d:\\s.txt");
file.write(c);
}
catch(Exception e) {
e.printStackTrace();
}
}
}
//从一个文件复制到另一个文件
package com.yourcompany.core;

import java.io.*;
import java.util.*;


public class Think {

public static void main(String[] args) {

try {

FileInputStream file = new FileInputStream("d:\\sss.txt");
FileOutputStream fileout = new FileOutputStream("d:\\aaa.txt");
byte[] c = new byte[file.available()];
for(int i = 0;i<c.length;i++) {
c[i] = (byte)file.read();
}
fileout.write(c);
}
catch(Exception e) {
e.printStackTrace();
}
}
}
//在屏幕上你输入什么我就输入什么
package com.yourcompany.core;

import java.io.*;
import java.util.*;


public class Think {

public static void main(String[] args) {

try {

byte [] c = new byte[1000];
int cc = System.in.read(c);
for (int i=0;i<cc;i++) {
System.out.print((char)c[i]);
}
}
catch(Exception e) {
e.printStackTrace();
}

}
}

Tags:java io 简单

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接