这篇文章主要回顾Java中和I/O操作相关的内容,I/O也是编程语言的一个基础特性,Java中的I/O分为两种类型,一种是顺序读取,一种是随机读取。

  我们先来看顺序读取,有两种方式可以进行顺序读取,一种是InputStream/OutputStream,它是针对字节进行操作的输入输出流;另外一种是Reader/Writer,它是针对字符进行操作的输入输出流。

  下面我们画出InputStream的结构

  aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsAAAAFhCAIAAADx5YtuAAAgAElEQVR4nO3du47jRhbGcW7SkxntsY3dhYONCBiYCTpcLJj6AfgChgHlGxjKNzD4BnoDwdFGihzqBQg4NBgZTvQCCibkBmd0tnhRNYtdJRaL/19g9EWXqo91OSLZ46wFsHIvLy9Zil5eXpaOFsBd2dINAPBWWZbmRE61X0AamJ/A6qW60abaLyANzE9g9VLdaFPtF5AG5ieweqlutKn2C0gD8xNYvVQ32lT7BaSB+Qms3r2Ntmmaoigul8u8l63rWr/e7XZFUZRlOfxVOBQQQMyYn8Dq3dto67rOsmz2Zp/nuTy3LEv5uqqqpmnqus7zfH5zJ6OAAGLG/ARW79UCoq5rOX+Q57mcRaiqSk4q5Hm+3+/bti3Lsqoq+UJkWZbneVVV8rDr9Sovm+e5/Kqu67Is9/u9lhd5nusLnk4n+VbOgpht2O128iw9peHULwAxYH4CqzelgMiy7HA4HI9H+Yls9qfT6XA45Hl+uVyKopACoiiKoijkNMPxeLxer1oKSGVwPB715ITUFufz+XK5yA+v16t8IT+Ub6uq0jYcDocsy3a7nTbGtV8AYsD8BFZvSgGhFx30bEFRFOZjegVEa1zCEFVVSQVgvpo+S15HTl3IE5um0W+lgJBnmRdWem8xsV8AYsD8BFZvXgEhPzmdTlmWye2WcoJhWEA0TaPPNUuBtltAmJc55Ff6ghQQQHqYn8DqzS4ghNyIsNvtsiyTSxJaQEjFID+RXzVN0zSNPNI8b9HeLmdo/VGWZVEUu92OMxBAkpifwOpZNlrdnntfyCUM+ZMK88FN01yvVznlIHc+ykkFqUL0kfpEebz5CvIi8u35fJ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ITfTdggLCguVmiHnkF2PskUjbLwqITfTdggLCguVmiHnkF2PskUjbLwqITfTdggLCguVmiHnkF2PskUjbLwqITfTdggLCguVmiHnkF2PskUjbLwqITfTdggLCguVmiHnkF2PskUjbLwqITfTdggLCguVmiHnkF2PskUjbLwqITfTdggLCguVmiHnkF2PskUjbLwqITfTdggLCguVmiHnkF2PskUjbLwqITfTdggLCguVmiHnkF2PskUjbLwqITfTdggLCguVmiHnkF2PskUjbryzLsufn52wDnp+fh/3fSN8terEQiGl0zCye0hdffLHguzOP/IpzjKWKtP16fn6m8gJW49tvv/348ePf/va3pRsCAC0FBLAOP/zww4cPHz59+vTdd9/9+9//Xro5ALaOAgJYgT///PObb775/fff27b99ddfv/nmm6VbBGDrKCCAFfj2229//vln/fb777//5z//uWB7AIACAoidXLwwf/LHH3+8f//+zz//XKpJAEABAUTNvHhh+umnn/7xj38s0SIAaFsKCCByvYsX6tOnT1999dV///vfxzcJAFoKCCBmw4sXpl9++eXvf//7I9sDAIoCAojUvYsXpg8fPvzwww8PaxIAKAoIIFL3Ll6Yfvvtty+//PIx7QEAEwUEECP7xQvTjz/+mOd56PYAQA8FBBCjd+/eTf9H6d+9e7d0ewFsDgUEsCYZ/+dAAHFgMQLWhAICQCRYjIA1oYAAEAkWI2BNKCAARILFCFgTCggAkWAxAtaEAgJAJFiMgDWhgAAQCRYjYE0oIABEgsUIWBMKCACRYDEC1oQCAkAkWIyANaGAABAJFiNgTSggAESCxQhYEwoIAJFgMQLWhAICQCRYjIA1oYAAEAkWI2BNKCAARILFCFgTCggAkWAxAtaEAgJAJFiMgDWhgAAQCRYjYE0oIABEgsUIWBMKCACRYDEC1oQCAkAkWIyANaGAABAJFiNgTSggAESCxQhYEwoIAJFgMQLWhAICQCRYjIA1oYAAEAkWI2BNKCAARILFCFgTCggAkWAxAtaEAgJAJFiMgDWhgAAQCRYjYE0oIABEgsVorV5eXjIA2/Dy8rL0kgP0UUCsVcYn0TAIdjaiC4dsESEG5VqxoARCsLM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aggPCOAiI0Etsyjn0HkyEQCogpKCC8o4AIjcS2jGPfwWQIhAJiCgoI7yggQiOxLePYdzAZAqGAmIICwjsKiNBIbMs49h1MhkAoIKaggPCOAiI0Etsyjn3H8/Pz6//3GLh7fn7mWLxqekobDGce14GXsR06IrEt49gDwGdsh65IbMs49gDwGduhKxLbMo49AHzGduiKxLaMYw8An3FziasZtzchGf8DBkQYrM8u7JwAAAAASUVORK5CYII=" alt="" width="633" height="301" />

  • FileInputStream:操作文件,经常和BufferedInputStream一起使用
  • PipedInputStream:可用于线程间通信
  • ObjectInputStream:可用于对象序列化
  • ByteArrayInputStream:用于处理字节数组的输入
  • LineNumberInputStream:可输出当前行数,并且可以在程序中进行修改

  下面是OutputStream的结构

  aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAi4AAAE3CAIAAAACGV1GAAAfqElEQVR4nO3dv67jxhnGYVbHbhKfxF44lbGBwTRulJ5VAF8AUxhIk0Z1Ot0CgTTu2ATBVroAQ2WKQDdAwEA65gK46VVsyRTfns8jSkdLUjNDfqPfUwTnDyUNX3HmJanjbNYDq7fZbLIUbTabpaMFViFbegDAp2VZmgdqqvsFTMVMgAGpLtmp7hcwFTMBBqS6ZKe6X8BUzAQYkOqSnep+AVMxE2BAqkt2qvsFTMVMgAGXS/Z+vy+KoiiKsizbtr36qNPp9Nqvbm98OBzkyff7fd/3bdueTqe5Y7+FKgIEMwEGDJbsqqqyLKuq6ng8FkWR5/nVR1VVVRTFyJfQjdu2zbKsruvj8bjb7fq+L4qiqqr79uA6qggQzAQYMFiy8zzfbrfyddd1eZ7v9/uqqsqy7Pu+rus8z5umyfM8yzL5Wq6f8jyXbW5vLFUkzy+1Jw+U55Gn6rpOnrAoiqZpuq6TUszz/HA46CBlA3mVoii6rruxX8DDYibAgMsqci9T5Fu9rKmqSq6Tdrud9IS2y+Fw0N56beO+78uyzLKsKIrj8Xg6nYqi2O12bdvK88jX2+1W6lAeeDqdjsdj3/fb7VaeWapIXlGeajDs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oJKoIqUl1rs5AFS2OKhqJKkJqUp2rM1BFi6OKRqKKkJpU/22xGfin8xbHP503Ev90HlKTJXraOMP9URDmnbwHmOo74mu/0kwHFqU6V2egihZHFY1EFSE1qc7VGaiixVFFI1FFSE2qc3UGqmhxVNFIVBFSk+pcnYEqWhxVNBJVhNSkOldnoIoWRxWNRBUhNanO1RmoosVRRSNRRUhNqnN1BqpocVTRSFQRUpPqXJ2BKlocVTQSVYTUpDpXZ6CKFkcVjUQVITWpztUZqKLFUUUjUUVITapzdQaqaHFU0UhUEVKT6lydgSpaHFU0ElWE1KQ6V2egihZHFY1EFSE1qc7VGaiixVFFI1FFSE2qc3UGqmhxVNFIVBFS8/z8/Ol/qOsxPD8/E+ay7n8LHuQd8RXU/wGfVnX7mXUJbgAAAABJRU5ErkJggg==" alt="" width="567" height="264" />

  • PrintStream:提供了类似print和println的接口去输出数据

  下面我们来看如何使用Stream的方式来操作输入输出

  • 使用InputStream读取文件

     
     public static byte[] readFileByFileInputStream(File file) throws IOException
    {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    FileInputStream fis = null;
    try
    {
    fis = new FileInputStream(file);
    byte[] buffer = new byte[1024];
    int bytesRead = 0;
    while((bytesRead = fis.read(buffer, 0, buffer.length)) != -1)
    {
    output.write(buffer, 0, bytesRead);
    }
    }
    catch(Exception ex)
    {
    System.out.println("Error occurs during reading " + file.getAbsoluteFile());
    }
    finally
    {
    if (fis !=null) fis.close();
    if (output !=null) output.close();
    }
    return output.toByteArray();
    }
     public static byte[] readFileByBufferedInputStream(File file) throws Exception
    {
    FileInputStream fis = null;
    BufferedInputStream bis = null;
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    try
    {
    fis = new FileInputStream(file);
    bis = new BufferedInputStream(fis);
    byte[] buffer = new byte[1024];
    int bytesRead = 0;
    while((bytesRead = bis.read(buffer, 0, buffer.length)) != -1)
    {
    output.write(buffer, 0, bytesRead);
    }
    }
    catch(Exception ex)
    {
    System.out.println("Error occurs during reading " + file.getAbsoluteFile());
    }
    finally
    {
    if (fis != null) fis.close();
    if (bis != null) bis.close();
    if (output != null) output.close();
    }
    return output.toByteArray();
    }
     
  • 使用OutputStream复制文件
     
     public static void copyFileByFileOutputStream(File file) throws IOException
    {
    FileInputStream fis = null;
    FileOutputStream fos = null;
    try
    {
    fis = new FileInputStream(file);
    fos = new FileOutputStream(file.getName() + ".bak");
    byte[] buffer = new byte[1024];
    int bytesRead = 0;
    while((bytesRead = fis.read(buffer,0,buffer.length)) != -1)
    {
    fos.write(buffer, 0, bytesRead);
    }
    fos.flush();
    }
    catch(Exception ex)
    {
    System.out.println("Error occurs during copying " + file.getAbsoluteFile());
    }
    finally
    {
    if (fis != null) fis.close();
    if (fos != null) fos.close();
    }
    }
     
     
     public static void copyFilebyBufferedOutputStream(File file)throws IOException
    {
    FileInputStream fis = null;
    BufferedInputStream bis = null;
    FileOutputStream fos = null;
    BufferedOutputStream bos = null;
    try
    {
    fis = new FileInputStream(file);
    bis = new BufferedInputStream(fis);
    fos = new FileOutputStream(file.getName() + ".bak");
    bos = new BufferedOutputStream(fos);
    byte[] buffer = new byte[1024];
    int bytesRead = 0;
    while((bytesRead = bis.read(buffer, 0, buffer.length)) != -1)
    {
    bos.write(buffer, 0, bytesRead);
    }
    bos.flush();
    }
    catch(Exception ex)
    {
    System.out.println("Error occurs during copying " + file.getAbsoluteFile());
    }
    finally
    {
    if (fis != null) fis.close();
    if (bis != null) bis.close();
    if (fos != null) fos.close();
    if (bos != null) bos.close();
    }
    }
     

    这里的代码对异常的处理非常不完整,稍后我们会给出完整严谨的代码。

  下面我们来看Reader的结构

  aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAiUAAAEOCAIAAADZjPDUAAAdiUlEQVR4nO2dr4/kyPmHjeYUkkx+naKgVSJLK4U0XGAaaeGZRAEBJ5kEHmhw/4AVkuiIpaDTgQZB0crooOERSwsCTo3CemBAg4H+gldT39ryuLs85bGr33oesOruKZfr/fit91Ou9uxkAwAAw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vCwW9c8Jsp0ol0HbTqqTUuCAe/ccFvpkgn0nXQqqfWuCAc/MYFv5kinUjXQaueWuOCcPAbF/xminQiXQetemqNC8LBb1zwmynSiXQdtOqpNS4IB79xwW+mSCfSddCqp9a4IBz8xgW/mSKdSNdBq55a44Jwsvv7+8k/ZJEk9/f3sxRMR8C5ysBltGYOeQJTsBIBAIA1+D8oPzLgQVvYjAAAAABJRU5ErkJggg==" alt="" width="549" height="235" />

  这里的Reader基本上和InputStream能够对应上。  

  Writer的结构如下

  aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAlwAAAEdCAIAAABWki6zAAAbDElEQVR4nO3dsY/jxtnHcVZrpEiythMj5QIBgQPcqDQMFm4CpAqOTZDyAP4DKVi4u4pIFbhhaxxgFSkPrFLqHyBwpcHKnbZMoWLLeYvn1WBM7nK4Gu4O9cz3Uxi61azI5+EMfyKl82UGwKzdbpdptNvtYrcW2Jws9g4AW5dlOpeJ1rqAEKwKwENreGitCwjBqgA8tIaH1rqAEKwKwENreGitCwjBqgA8tIaH1rqAEKwKwCM8PJqmORwO08dt29rHxpjj8VgUxTAMgZtbiFAEplgVgEd4eOR5XlWVMWYYhizLiqKwP3dD0RjTNM3pdJKn+r4P3O48QhGYYlUAHuHhUdd1nufGmLZt8zyXx33fy4Oqqvb7vVwjlmU5DENVVZKdbdsej8eqqoqiaJrGGCPP1nUtKRu3LkAfVgXgER4eh8NB8q8sy6qq5CqwaRq5ZCyKIs/zuq5Pp5M8JdlZ1/XhcJBfkQRt27bv+yzLyrJs2zZ6XYA+rArAY5XwyPO86zrJvDzPJRHl4q8oirqu7TC5a+o+qOu6aRr5LXt9GY5QBKZYFYDHKuFRFEVZlvZ+qVwdSuzZdDRPhOJ+v+/7vu/70+lEKAIvilUBeKwSHnVd26/Y7Pf7LMtstj0VilVVdV1XlqUMqOt6GAZCEXhRrArAY5XwGIahaZqu6+SPTdPYDwXdv5hhv33adZ39yxtt2zZNI8F5Op1sggYiFIEpVgXgoTU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k9eKs9zuUaU16mqKsuyoijath29lGwiz/OqqlYvCkgHqwLwu+z2qZmEotwX7fte8kzumsqzXdfled62bVmWck+1KAqbcDJs9MB9KXt9+RJFAelgVQB+F98+nYZiXddN09jbnnJtJ8+WZVmWZZ7n8pSknfs6owfuSz31seUqRQHpYFUAfmuFolz89X1/OBzk26SSiPKs3Di12fZUKMpnjaOXIhSBVbAqAL/l+VFVlfupnnxZ1P6VDHkgwSm3OruuK4rCfgfVvWVaVZX91oz90mld1/KZ4uilnvpbH6sUBaSDVQH4qcwPlUUBgVgVgJ/K/FBZFBCIVQH4qcwPlUUBgVgVgJ/K/FBZFBCIVQH4qcwPlUUBgVgVgJ/K/FBZFBCIVQH43dzcZOrc3NzE7iuwOYQi4JdpvKhSWRQQiFUB+KnMD5VFAYFYFYCfyvxQWRQQiFUB+KnMD5VFAYFYFYCfyvxQWRQQiFUB+KnMD5VFAYFYFYCfyvxQWRQQiFUB+KnMD5VFAYFYFYCfyvxQWRQQiFUB+KnMD5VFAYFYFYCfyvxQWRQQiFUB+KnMD5VFAYFYFYCfyvxQWRQQiFUB+KnMD5VFAYFYFYCfyvxQWRQQiFUB+KnMD5VFAYFYFYAf/8gwkAhCEfDLNF5UqSwKCMSqAPxU5ofKooBArArAT2V+qCwKCMSqAPxU5ofKooBArArAT2V+qCwKCMSqAPxU5ofKooBArArAT2V+qCwKCMSqAPxU5ofKooBArArAT2V+qCwKCMSqAPxU5ofKooBArArAT2V+qCwKCMSqAPxU5ofKooBArArAT2V+qCwKCMSqAPxU5ofKooBArArAT2V+qCwKCMSqAPxU5ofKooBArArA7/b29uX/0d/Xdnt7G7uvwOb8H3PabMMAtvB9AAAAAElFTkSuQmCC" alt="" width="604" height="257" />

  下面我们来看一些使用Reader或者Writer的例子

  • 使用Reader读取文件内容

     
     public static String readFile(String file)throws IOException
    {
    BufferedReader br = null;
    StringBuffer sb = new StringBuffer();
    try
    {
    br = new BufferedReader(new FileReader(file));
    String line = null; while((line = br.readLine()) != null)
    {
    sb.append(line);
    }
    }
    catch(Exception ex)
    {
    System.out.println("Error occurs during reading " + file);
    }
    finally
    {
    if (br != null) br.close();
    }
    return sb.toString();
    }
     
  • 使用Writer复制文件
     
     public static void copyFile(String file) throws IOException
    {
    BufferedReader br = null;
    BufferedWriter bw = null;
    try
    {
    br = new BufferedReader(new FileReader(file));
    bw = new BufferedWriter(new FileWriter(file + ".bak"));
    String line = null;
    while((line = br.readLine())!= null)
    {
    bw.write(line);
    }
    }
    catch(Exception ex)
    {
    System.out.println("Error occurs during copying " + file);
    }
    finally
    {
    if (br != null) br.close();
    if (bw != null) bw.close();
    }
    }
     

  下面我们来看如何对文件进行随机访问,Java中主要使用RandomAccessFile来对文件进行随机操作。

  • 创建一个大小固定的文件

     
     public static void createFile(String file, int size) throws IOException
    {
    File temp = new File(file);
    RandomAccessFile raf = new RandomAccessFile(temp, "rw");
    raf.setLength(size);
    raf.close();
    }
     
  • 向文件中随机写入数据
     
     public static void writeFile(String file, byte[] content, int startPos, int contentLength) throws IOException
    {
    RandomAccessFile raf = new RandomAccessFile(new File(file), "rw");
    raf.seek(startPos);
    raf.write(content, 0, contentLength);
    raf.close();
    }
     

  接下里,我们来看一些其他的常用操作

  • 移动文件

     
     public static boolean moveFile(String sourceFile, String destFile)
    {
    File source = new File(sourceFile);
    if (!source.exists()) throw new RuntimeException("source file does not exist.");
    File dest = new File(destFile);
    if (!(new File(dest.getPath()).exists())) new File(dest.getParent()).mkdirs();
    return source.renameTo(dest);
    }
     
  • 复制文件
     
     public static void copyFile(String sourceFile, String destFile) throws IOException
    {
    File source = new File(sourceFile);
    if (!source.exists()) throw new RuntimeException("File does not exist.");
    if (!source.isFile()) throw new RuntimeException("It is not file.");
    if (!source.canRead()) throw new RuntimeException("File cound not be read.");
    File dest = new File(destFile);
    if (dest.exists())
    {
    if (dest.isDirectory()) throw new RuntimeException("Destination is a folder.");
    else
    {
    dest.delete();
    }
    }
    else
    {
    File parentFolder = new File(dest.getParent());
    if (!parentFolder.exists()) parentFolder.mkdirs();
    if (!parentFolder.canWrite()) throw new RuntimeException("Destination can not be written.");
    }
    FileInputStream fis = null;
    FileOutputStream fos = null;
    try
    {
    fis = new FileInputStream(source);
    fos = new FileOutputStream(dest);
    byte[] buffer = new byte[1024];
    int bytesRead = 0;
    while((bytesRead = fis.read(buffer, 0, buffer.length)) != -1)
    {
    fos.write(buffer, 0, bytesRead);
    }
    fos.flush();
    }
    catch(IOException ex)
    {
    System.out.println("Error occurs during copying " + sourceFile);
    }
    finally
    {
    if (fis != null) fis.close();
    if (fos != null) fos.close();
    }
    }
     
  • 复制文件夹
     
     public static void copyDir(String sourceDir, String destDir) throws IOException
    { File source = new File(sourceDir);
    if (!source.exists()) throw new RuntimeException("Source does not exist.");
    if (!source.canRead()) throw new RuntimeException("Source could not be read.");
    File dest = new File(destDir);
    if (!dest.exists()) dest.mkdirs(); File[] arrFiles = source.listFiles();
    for(int i = 0; i < arrFiles.length; i++)
    {
    if (arrFiles[i].isFile())
    {
    BufferedReader reader = new BufferedReader(new FileReader(arrFiles[i]));
    BufferedWriter writer = new BufferedWriter(new FileWriter(destDir + "/" + arrFiles[i].getName()));
    String line = null;
    while((line = reader.readLine()) != null) writer.write(line);
    writer.flush();
    reader.close();
    writer.close();
    }
    else
    {
    copyDir(sourceDir + "/" + arrFiles[i].getName(), destDir + "/" + arrFiles[i].getName());
    }
    }
    }
     
  • 删除文件夹
     
     public static void del(String filePath)
    {
    File file = new File(filePath);
    if (file == null || !file.exists()) return;
    if (file.isFile())
    {
    file.delete();
    }
    else
    {
    File[] arrFiles = file.listFiles();
    if (arrFiles.length > 0)
    {
    for(int i = 0; i < arrFiles.length; i++)
    {
    del(arrFiles[i].getAbsolutePath());
    }
    }
    file.delete();
    }
    }
     
  • 获取文件夹大小
     
     public static long getFolderSize(String dir)
    {
    long size = 0;
    File file = new File(dir);
    if (!file.exists()) throw new RuntimeException("dir does not exist.");
    if (file.isFile()) return file.length();
    else
    {
    String[] arrFileName = file.list();
    for (int i = 0; i < arrFileName.length; i++)
    {
    size += getFolderSize(dir + "/" + arrFileName[i]);
    }
    } return size;
    }
     
  • 将大文件切分为多个小文件
     
     public static void splitFile(String filePath, long unit) throws IOException
    {
    File file = new File(filePath);
    if (!file.exists()) throw new RuntimeException("file does not exist.");
    long size = file.length();
    if (unit >= size) return;
    int count = size % unit == 0 ? (int)(size/unit) : (int)(size/unit) + 1;
    String newFile = null;
    FileOutputStream fos = null;
    FileInputStream fis =null;
    byte[] buffer = new byte[(int)unit];
    fis = new FileInputStream(file);
    long startPos = 0;
    String countFile = filePath + "_Count";
    PrintWriter writer = new PrintWriter(new FileWriter( new File(countFile)));
    writer.println(filePath + "\t" + size);
    for (int i = 1; i <= count; i++)
    {
    newFile = filePath + "_" + i;
    startPos = (i - 1) * unit;
    System.out.println("Creating " + newFile);
    fos = new FileOutputStream(new File(newFile));
    int bytesRead = fis.read(buffer, 0, buffer.length);
    if (bytesRead != -1)
    {
    fos.write(buffer, 0, bytesRead);
    writer.println(newFile + "\t" + startPos + "\t" + bytesRead);
    }
    fos.flush();
    fos.close();
    System.out.println("StartPos:" + i*unit + "; EndPos:" + (i*unit + bytesRead));
    }
    writer.flush();
    writer.close();
    fis.close();
    }
     
  • 将多个小文件合并为一个大文件
     
     public static void linkFiles(String countFile) throws IOException
    {
    File file = new File(countFile);
    if (!file.exists()) throw new RuntimeException("Count file does not exist.");
    BufferedReader reader = new BufferedReader(new FileReader(file));
    String line = reader.readLine();
    String newFile = line.split("\t")[0];
    long size = Long.parseLong(line.split("\t")[1]);
    RandomAccessFile raf = new RandomAccessFile(newFile, "rw");
    raf.setLength(size);
    FileInputStream fis = null;
    byte[] buffer = null; while((line = reader.readLine()) != null)
    {
    String[] arrInfo = line.split("\t");
    fis = new FileInputStream(new File(arrInfo[0]));
    buffer = new byte[Integer.parseInt(arrInfo[2])];
    long startPos = Long.parseLong(arrInfo[1]);
    fis.read(buffer, 0, Integer.parseInt(arrInfo[2]));
    raf.seek(startPos);
    raf.write(buffer, 0, Integer.parseInt(arrInfo[2]));
    fis.close();
    }
    raf.close();
    }
     
  • 执行外部命令
     
     public static void execExternalCommand(String command, String argument)
    {
    Process process = null;
    try
    {
    process = Runtime.getRuntime().exec(command + " " + argument);
    InputStream is = process.getInputStream();
    BufferedReader br = new BufferedReader(new InputStreamReader(is));
    String line = null;
    while((line = br.readLine()) != null)
    {
    System.out.println(line);
    }
    }
    catch(Exception ex)
    {
    System.err.println(ex.getMessage());
    }
    finally
    {
    if (process != null) process.destroy();
    }
    }

Java回顾之I/O的更多相关文章

  1. Java回顾之Spring基础

    第一篇:Java回顾之I/O 第二篇:Java回顾之网络通信 第三篇:Java回顾之多线程 第四篇:Java回顾之多线程同步 第五篇:Java回顾之集合 第六篇:Java回顾之序列化 第七篇:Java ...

  2. Java回顾之ORM框架

    这篇文章里,我们主要讨论ORM框架,以及在使用上和JDBC的区别. 概述 ORM框架不是一个新话题,它已经流传了很多年.它的优点在于提供了概念性的.易于理解的数据模型,将数据库中的表和内存中的对象建立 ...

  3. Java回顾之多线程同步

    在这篇文章里,我们关注线程同步的话题.这是比多线程更复杂,稍不留意,我们就会“掉到坑里”,而且和单线程程序不同,多线程的错误是否每次都出现,也是不固定的,这给调试也带来了很大的挑战. 在这篇文章里,我 ...

  4. java回顾(项目前期的基本准备)

    一.     基础回顾 1   集合 1.1 集合的类型与各自的特性 ---|Collection: 单列集合 ---|List: 有存储顺序, 可重复 ---|ArrayList:  数组实现, 查 ...

  5. Java回顾之多线程

    在这篇文章里,我们关注多线程.多线程是一个复杂的话题,包含了很多内容,这篇文章主要关注线程的基本属性.如何创建线程.线程的状态切换以及线程通信,我们把线程同步的话题留到下一篇文章中. 线程是操作系统运 ...

  6. java回顾rmi

    搞java的不懂rmi好像说不过去.. ,复习一遍. 参照http://www.iteye.com/topic/173909 http://lzj0470.iteye.com/blog/426760  ...

  7. java回顾巩固

    看视频复习java有一段时间了.虽然现在做的东西是net的,但是一直没忘记复习java. 更多的大概在这里. java变量的命名规则: (A)组成规则: 1:英文大小写字母 2:数字 3:$和_ (2 ...

  8. java回顾4 Java基本数据类型

    为JAVA基本数据类型.我的实在是有兴趣引用数据类型.在这里,我说的是主应用程序数据类型. 为JAVA荐两个网址: 1.http://blog.sina.com.cn/s/blog_745b874b0 ...

  9. Java回顾之JDBC

    这篇文章里,我们来讨论一些和JDBC相关的话题. 概述 尽管在实际开发过程中,我们一般使用ORM框架来代替传统的JDBC,例如Hibernate或者iBatis,但JDBC是Java用来实现数据访问的 ...

随机推荐

  1. 微信小程序 --- 绘画

    cavans及context详解 绘画API的使用 游戏的制作

  2. List<Map<String, Object>> 与 json 互转

    近期做指纹识别,需要用到缓存文件,数据量并不大,用redis不合适,所以用到了txt文件. 思路是 1.定时查询指纹,存到txt缓存文件中.      2.新增或删除指纹时,查询指纹,存到txt缓存文 ...

  3. Oracle之catalog恢复目录的创建于维护(51CTO风哥rman课程)

    catalog恢复目录配置过程 1,创建一个表空间 2,创建rman用户并授权 3,创建恢复目录 4,配置TNS 5,注册数据库 6,检查 创建ramn表空间 首先查看一下其他表空间位置 create ...

  4. Object类中常见的方法,为什么wait notify会放在Object里边

    toString():输出一个对象的地址字符串(哈希code码):可以通过重写toString方法,获取对象的属性! equals():比较的是对象的引用是否指向同一块内存地址, 重写equals() ...

  5. 控制HttpContext为null

    直接new一个 HttpContextBase _HttpContext= new HttpContextWrapper(System.Web.HttpContext.Current);

  6. 简单的共享文件http

    如果你急需一个简单的Web Server,但你又不想去下载并安装那些复杂的HTTP服务程序,比如:Apache,ISS等.那么, Python 可能帮助你.使用Python可以完成一个简单的内建 HT ...

  7. centos shell脚本编程2 if 判断 case判断 shell脚本中的循环 for while shell中的函数 break continue test 命令 第三十六节课

    centos  shell脚本编程2 if 判断  case判断   shell脚本中的循环  for   while   shell中的函数  break  continue  test 命令   ...

  8. 102-advanced-代码分割

    1.Bundling 大多数React应用程序将使用Webpack或Browserify等工具“捆绑”文件.捆绑是跟踪导入的文件并将它们合并到单个文件中的过程:“捆绑”.然后,该包可以包含在网页中以一 ...

  9. Android初体验之Monkey和MonkeyRunner

    原文地址https://blog.csdn.net/mad1989/article/details/38087737 Monkey 什么是Monkey Monkey是Android中的一个命令行工具, ...

  10. Cocos2d-JS实现的2048

    一.前言 2048是之前火过一段时间的休闲数字消除类游戏,它的玩法很简单,上手很容易,可是想到要得到高分却很难,看似简单的游戏却有着很多得分的技巧,想当初这个游戏也曾是陪伴我大学课堂的游戏之一.虽然在 ...