服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

通过文件名打开文件

/*
 * copyright (c) ian f. darwin, http://www.darwinsys.com/, 1996-2002.
 * all rights reserved. software written by ian f. darwin and others.
 * $id: license,v 1.8 2004/02/09 03:33:38 ian exp $
 *
 * redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * this software is provided by the author and contributors ``as is''
 * and any express or implied warranties, including, but not limited
 * to, the implied warranties of merchantability and fitness for a particular
 * purpose are disclaimed.  in no event shall the author or contributors
 * be liable for any direct, indirect, incidental, special, exemplary, or
 * consequential damages (including, but not limited to, procurement of
 * substitute goods or services; loss of use, data, or profits; or business
 * interruption) however caused and on any theory of liability, whether in
 * contract, strict liability, or tort (including negligence or otherwise)
 * arising in any way out of the use of this software, even if advised of the
 * possibility of such damage.
 
 * java, the duke mascot, and all variants of sun's java "steaming coffee
 * cup" logo are trademarks of sun microsystems. sun's, and james gosling's,
 * pioneering role in inventing and promulgating (and standardizing) the java 
 * language and environment is gratefully acknowledged.
 
 * the pioneering role of dennis ritchie and bjarne stroustrup, of at&t, for
 * inventing predecessor languages c and c++ is also gratefully acknowledged.
 */


import java.io.*;
public class openfilebyname {
  public static void main(string[] argsthrows ioexception {
    bufferedreader is = new bufferedreader(new filereader("myfile.txt"));
    bufferedoutputstream bytesout = new bufferedoutputstream(
      new fileoutputstream("bytes.dat"));

    // code here to read from is, write to bytesout

    bytesout.close();
  }
}

扫描关注微信公众号