It's not using JDK, I think. Because the copy method will invoke Windows' methods...
FileOutputStream out = new FileOutputStream(file, true); java.io.FileReader fileReaderObj = new java.io.FileReader("D:\\2\\5.txt"); BufferedReader bufferedReaderObj = new BufferedReader(fileReaderObj); while ((strVal = bufferedReaderObj.readLine()) != null) { out.write(strVal.getBytes("GB2312"));}
File file = new File("C:\\Documents and Settings\\1212.doc"); if (!file.exists()) { file.createNewFile(); } FileOutputStream out = new FileOutputStream(file, true); StringBuffer sb = new StringBuffer(); java.io.FileReader fileReaderObj = new java.io.FileReader("C:\\Documents and Settings\\1.txt"); BufferedReader bufferedReaderObj = new BufferedReader(fileReaderObj); while ((strVal = bufferedReaderObj.readLine()) != null) { sb.append(strVal); } out.write(sb.toString().getBytes("UTF-8")); out.close();
FileOutputStream fos = new FileOutputStream( "C:/bbb/test.txt ");
byte[] buff = new byte[1024];
int readed = -1;
while((readed = fis.read(buff)) > 0)
fos.write(buff, 0, readed);
fis.close();
fos.close();
FileChannel outChannel = new FileOutputStream(out).getChannel();
try {
inChannel.transferTo(0, inChannel.size(), outChannel);
}
catch (IOException e) {
throw e;
}
public static String readFile(String fileName) {
String output = "";
File file = new File(fileName);
if(file.exists()){
if(file.isFile()){
try{
BufferedReader input = new BufferedReader (new FileReader(file));
StringBuffer buffer = new StringBuffer();
String text;
while((text = input.readLine()) != null)
buffer.append(text +"\n");
output = buffer.toString();
}
catch(IOException ioException){
System.err.println("File Error!"); }
}
else if(file.isDirectory()){
String[] dir = file.list();
output += "Directory contents:\n";
for(int i=0; i<dir.length; i++){
output += dir[i] +"\n";
}
}
}
else{
System.err.println("Does not exist!");
}
return output;
}
java.io.FileReader fileReaderObj = new java.io.FileReader("D:\\2\\5.txt");
BufferedReader bufferedReaderObj = new BufferedReader(fileReaderObj);
while ((strVal = bufferedReaderObj.readLine()) != null) {
out.write(strVal.getBytes("GB2312"));}
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream out = new FileOutputStream(file, true);
StringBuffer sb = new StringBuffer();
java.io.FileReader fileReaderObj = new java.io.FileReader("C:\\Documents and Settings\\1.txt");
BufferedReader bufferedReaderObj = new BufferedReader(fileReaderObj);
while ((strVal = bufferedReaderObj.readLine()) != null) {
sb.append(strVal);
}
out.write(sb.toString().getBytes("UTF-8"));
out.close();
boolean cont = true; // 循环控制变量
FileOutputStream outfile = null; // 文件输出对象 // 生成对象outfile,准备输出到文件
try
{
outfile = new FileOutputStream(args[0]);
}
catch (FileNotFoundException e)
{
System.err.println("文件不存在");
System.exit(1);
} // 行首没有输入句号时执行如下循环
while (cont)
{
try
{
int n = System.in.read(buff); // 从System.in读入数据
System.out.write(buff, 0, n); // 写入到System.out中
if (buff[0]==´#´)
{
cont = false;
}
else
{
outfile.write(buff, 0, n);
}
* @param src 文件源目录
* @param dest 文件目的目录
* @throws IOException
*/public void copyFile(String src,String dest) throws IOException...{
FileInputStream in=new FileInputStream(src);
File file=new File(dest);
if(!file.exists())
file.createNewFile();
FileOutputStream out=new FileOutputStream(file);
int c;
byte buffer[]=new byte[1024];
while((c=in.read(buffer))!=-1)...{
for(int i=0;i<c;i++)
out.write(buffer[i]);
}
in.close();
out.close();
}
FileChannel inChannel = new FileInputStream("C:/ntldr").getChannel();
FileChannel outChannel = new FileOutputStream("C:/ntldr.bak").getChannel();
inChannel.transferTo(0, Integer.MAX_VALUE, outChannel);
inChannel.close();
outChannel.close();
long end = System.currentTimeMillis();
System.out.println("transfer over, spend time : " + (end - start) + " ms.");
class Student implements Cloneable
{
String name;
int age;
Student(String name,int age)
{
this.name=name;
this.age=age;
}
public Object clone()
{
Object o=null;
try
{
o=(Student)super.clone();
}
catch(CloneNotSupportedException e)
{
System.out.println(e.toString());
}
return o;
}
}
public static void main(String[] args)
{
Student s1=new Student("a",1);
Student s2=(Student)s1.clone();
s2.name="";
s2.age=20;
System.out.println("name="+s1.name+","+"age="+s1.age);//修改学生2后,不影响学生1的值。
}这种?