`
djsl6071
  • 浏览: 578053 次
  • 性别: Icon_minigender_1
  • 来自: 厦门
社区版块
存档分类
最新评论

file.renameTo() test.

 
阅读更多

 

private void testFileIO(String fileName) {

  try {
   File file = new File(fileName);
   FileOutputStream fos = new FileOutputStream(file);
   byte[] byteArray = new byte[10];   
   byteArray[0] = 1;
   byteArray[4]=1;
   fos.write(byteArray);
   fos.close();   
   
   FileInputStream fis;
   fis= new FileInputStream(file);
   while (fis.available() > 0){
    System.out.print(fis.read());
   }
   fis.close();
   file.createNewFile();
   
   System.out.print("\n");
   File file2 = new File("654321.bin");
   //file2.createNewFile();
   //file2 should be created before as arg of renameTo()
   System.out.println(file.renameTo(file2));
   //renameTo may create the old file and the new file,transmit data from old to new.


   //old 0,new 0,success,old none,new created
   //old 1,new 0,success,old none,new created

//目标文件不存在时,总能成功,源文件被重命名


   //old 0,new 1,fail,old created,new null
   //old 1,new 1,fail,old created,new null

//目标文件存在时,总是失败,源文件在目录中存在并为原文件名(不论之前是否创建)


   System.out.println(file.getName());
   
   
   fis = new FileInputStream(file);
   while (fis.available() > 0){
    System.out.print(fis.read());
   }
   fis.close();
   
   
   //file对象中可读写数据而无须物理上的存在。
  } catch (FileNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

 }

分享到:
评论

相关推荐

    Doctrine ORM for PHP.pdf

    Test Script..........................................................................................................................23 Conclusion.........................................................

    MICROSOFT FOUNDATION CLASS LIBRARY

    named Test.pch and a precompiled types file named StdAfx.obj. Resource.h This is the standard header file, which defines new resource IDs. Microsoft Visual C++ reads and updates this file. //////...

    ORACLE OSB开发指南

    1 Introduction to Oracle Service Bus 2 Tasks Working with Projects, Folders, Resources, and Configurations ................................................... 2-1 Resource Naming Restrictions ...........

    VB编程资源大全(英文源码 文件)

    Use Kill to remove the original file and then use Name to give the temporary file the old file name."<END><br>8 , cpyfile.zip This will copy a specified file to a directory. It also shows its ...

    apktool documentation

    After you find a framework file you could pull it via adb pull /path/to/file or use a file manager application. After you have the file locally, pay attention to how Apktool installs it. The number ...

    IO输入输出留

    System.out.println("文件名是否更改成功:" + f1.renameTo(f2)); // 改名以后的的状态 System.out.println(f1.getName() + "是否存在" + f1.exists()); System.out.println(f2.getName() + "是否存在" + f2...

    delphi.fast.zlib.v.1.21

    average faster than native DLL distribution and 100% reliable (original test of zlib 1.1.4 version).How to compress and decompress a file:procedure TForm1.Button1Click(Sender: TObject);var InputStream...

    convmv-1.15.tar.gz

    When Netatalk is being switched to UTF-8 which is supported in version 2 then it is NOT sufficient to rename the file names. There needs to be done more. See ...

    UNIX环境高级编程(第二版,英文版)

    Systems Used to Test the Examples Acknowledgments Chapter 1. UNIX System Overview Section 1.1. Introduction Section 1.2. UNIX Architecture Section 1.3. Logging In ...

    VclZip pro v3.10.1

    Fixed the SFX code so that it works properly if you use Copy /B to concatenate a zip file to the stub. Due to a Delphi strange behavior sometimes path names for directory only entries would become ...

    ICS delphixe10源码版

    ICS - Internet Component Suite - V8 - Delphi 7 to RAD Studio 10 Seattle ======================================================================= ...Rename the old ICS directory and unzip to...

    Senfore_DragDrop_v4.1

    A batch file, convert_forms_to delphi_4_format.bat, is supplied in the demo directory which automates the conversion process. The C++ Builder demo forms are distributed in binary format. 7) If ...

    [Mastering.Node.js(2013.11) 精通Node.js

    Using Grunt, Mocha, and PhantomJS to test and deploy projects 281 Working with Grunt 283 Summary 284 Appendix A: Organizing Your Work 285 Loading and using modules 286 Understanding the module object ...

    PLSQL.Developer v11.0.0.1762 主程序+ v10中文包+keygen

    A new Export/Import function allows you to export specific preference sections to a file, and to import them on another PC. The following preferences options have been added: Files/Format/Encoding: ...

    最全的oracle常用命令大全.txt

    Connected to an idle instance. SQL> startup^C SQL> startup ORACLE instance started. 2、在双机环境下 要想启动或关闭ORACLE系统必须首先切换到root用户,如下 su - root a、启动ORACLE系统 hareg -y ...

    Linux高级bash编程

    几个等效命令test,/usr/bin/test,[],和/usr/bin/[ 7-3. 算数测试使用(( )) 7-4. test死的链接文件 7-5. 数字和字符串比较 7-6. 测试字符串是否为null 7-7. zmore 8-1. 最大公约数 8-2. 使用算术操作符 8-3. 使用&&...

    Advanced Bash-Scripting Guide <>

    几个等效命令test,/usr/bin/test,[],和/usr/bin/[ 7-3. 算数测试使用(( )) 7-4. test 死的链接文件 7-5. 数字和字符串比较 7-6. 测试字符串是否为null 7-7. zmore 8-1. 最大公约数 8-2. 使用算术操作符 8-3. 使用&&...

    windows copy (复制) 工具

    Copy the file to the new location and rename it right away. example4: ycopy.exe -s=C:\Users\Yun Liu\Desk*\test\*Temp\*source*.txt;-b=C:\Users\Yun Liu\Desktop\test\backup\2010source.txt;-i=0;/o Only ...

    Kaggle-Dogs_vs_Cats_PyTorch:kaggle比赛

    git clone https://github.com/JackwithWilshere/Kaggle-Dogs_vs_Cats_PyTorch第2步: from the website https://www.kaggle.com/c/dogs-vs-cats/data download the file train and test1 to the file "./data" ...

    Linux下的rar解压缩工具

    cw Write archive comment to file d Delete files from archive e Extract files without archived paths f Freshen files in archive i[par]=&lt;str&gt; Find string in archives k Lock archive l[t[a],b] List...

Global site tag (gtag.js) - Google Analytics