`
arlord
  • 浏览: 5070 次
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

IO About file copy

 
阅读更多
package demo;

import java.io.*;

public class TestCopy{
public void testCopy()throws Exception{
FileInputStream fis = new FileInputStream("c:/爱是永恒.mp3");
int offset = 0;
FileOutputStream fos = new FileOutputStream("d:/test.mp3");
while((offset = fis.read()) != -1){
fos.write(offset);
}
fis.close();
fos.close();
}

//使用缓存来提高效率
public void testCopy2()throws Exception{
FileInputStream fis = new FileInputStream("c:/爱是永恒.mp3");
//定义一个缓存用来装载读取到的文件
byte[] temp = new byte[1024];
int offset = 0;
FileOutputStream fos = new FileOutputStream("d:/test2.mp3");
//fis.read(temp) 把文件内容读取到temp数组,读到temp满为止或者没有内容
//fis.read(temp)的返回值是实际读取进数组的字节个数
while((offset = fis.read(temp)) != -1){
//每次把一整个数组的数据写入文件,0表示从temp的第0个位置开始读取,
//一共读取offset个写入到内容
fos.write(temp,0,offset);
}
fis.close();
fos.close();
}

public static void main(String[] args)throws Exception{
TestCopy t = new TestCopy();
t.testCopy2();
}
}
分享到:
评论

相关推荐

    Android代码-FlipGank

    FlipGank download apk 一款 FlipBoard 翻页风格的 Gank.io ... you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/

    go系统编程(英文版)

    program that uses signals to present the progress of a file copy operation. This chapter will also teach you how to plot data in Go and how to implement Unix pipes in Go. Then it will implement the ...

    swing文件拖拽

    import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.Iterator; import java.util.List; import javax.swing.Icon; import ...

    C# 记事本代码

    using System.IO; namespace Mickey记事本 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } // 用于存储当前操作的文件的名称 private string textFileName = ""; ...

    apktool documentation

    Used with -c / --copy-original on [b]uild unknown = Files / folders that are not part of the standard AOSP build procedure. These files will be injected back into the rebuilt APK. apktool.yml ...

    javacv-platform-1.3.3-src

    import java.io.File; import java.net.URL; import org.bytedeco.javacv.*; import org.bytedeco.javacpp.*; import org.bytedeco.javacpp.indexer.*; import static org.bytedeco.javacpp.opencv_core.*; import ...

    BobBuilder_app

    Automatic index file recovery on non-clean shutdowns. String Keys are UTF8 encoded and limited to 60 bytes if not specified otherwise (maximum is 255 chars). Support for long string Keys with the ...

    python3.6.5参考手册 chm

    PEP 519: Adding a file system path protocol PEP 495: Local Time Disambiguation PEP 529: Change Windows filesystem encoding to UTF-8 PEP 528: Change Windows console encoding to UTF-8 PEP 520: ...

    occam一维反演

    c ITER00 is a copy of the startup file at iteration 0. Any ITER file can be re- c named startup to continue an inversion. c c As the response of the model in dm() is not necessarily the response of ...

    VB.NET Developer's Guide(4574).pdf

    File I/O 155 Drawing 156 Printing 157 Common Type System 158 Type Casting 160 Garbage Collection 163 Object Allocation/Deallocation 164 Close/Dispose 165 Summary 166 Solutions Fast Track 167...

    8-07-14_MegaCLI for linux_windows

    SCGCQ00521386 (DFCT) - Megacli : ADRA is still mentioned in help file, eventhough it is not supported SCGCQ00572235 (DFCT) - No description for "setdelay" with help file of adppr. SCGCQ00572270 (DFCT)...

    Bochs - The cross platform IA-32 (x86) emulator

    boot sector from file, volatile write support using hdimage redolog_t class, optional commit support on Bochs exit, save/restore file attributes, 1.44 MB floppy support, set file modification date/...

    tomcat-5.5.23

    temp - Directory used by the JVM for temporary files (java.io.tmpdir) <br>If you do not pass the "-Dcatalina.base=$CATALINA_BASE" argument to the startup command, $CATALINA_BASE will default to ...

    acpi控制笔记本风扇转速

    Moved all FADT-related functions to a new file, tbfadt.c. Eliminated the AcpiHwInitialize function - the FADT registers are now validated when the table is loaded. Added two new warnings during FADT ...

Global site tag (gtag.js) - Google Analytics