Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Java to achieve local fileCopy     - Oracle Database Performance Optimization of memory disk (Database)

- Ubuntu simple method to track multiple time zones (Linux)

- How to turn Java String into Date (Programming)

- Ubuntu users how to install the latest Nvidia graphics drivers (Linux)

- Java data structures - the linear form of the single-chain applications (Programming)

- wget command examples (Linux)

- Windows Ubuntu dual system a key Ghost, grub rescue prompt solution (Linux)

- Oracle table space is too large processing time (Database)

- JavaScript original values and complex values (Programming)

- MySQL function: group_concat () function (Database)

- FFmpeg compiled with only H264 decoding library (Programming)

- C ++ sequence containers basics summary (Programming)

- Java reflection summary (Programming)

- Present Situation and Development Trend of firewall products (Linux)

- Java multithreading easy to confuse the concept (Programming)

- Java concurrent programming using the synchronized keyword ReentrantLock alternative primitive (Programming)

- Migrate Oracle database files to ASM (Database)

- DB2 Version SQLJ to access Oracle Server (Database)

- Teach you how to choose to install CentOS 6.5 installation package (Linux)

- Learning how to teach safety system to prevent your own IP leakage (Linux)

 
         
  Java to achieve local fileCopy
     
  Add Date : 2018-11-21      
         
         
         
  1.Java flows is an important content of basic reading and writing files and copy knowledge test sites is a lot of interviews. Therefore, through this paper, a simple test summary.

2. The figure shows the text [IO / Binary IO]

3. Copy the text experimental Java implementation code:

package com.gdufe.io;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class TestInputOutputStream {

// Private final static String SOURCE = "t.txt";
// Private final static String TARGET = "tt.txt";
// Private final static String SOURCE = "p.png";
// Private final static String TARGET = "pp.png";
    private final static String SOURCE = "D: \\ Tool_Software \\ mysql-installer-community-5.6.23.0.msi";
    private final static String TARGET = "mysql-installer-community-5.6.23.0.msi";
    //D:\Tool_Software\Ryuyan.zip
    
    
    public static void main (String [] args) {
// TestInputOutputStream.copy1 (SOURCE, TARGET);
// TestInputOutputStream.copy2 (SOURCE, TARGET);
        TestInputOutputStream.copy3 (SOURCE, TARGET);
        System.out.println ( "- End ---");
    }
    
    public static void copy1 (String src, String tar) {
        
        InputStream input = null;
        OutputStream output = null;
        try {
            input = new FileInputStream (src);
            output = new FileOutputStream (tar);
            int r;
            while ((r = input.read ()) = -! 1) {
                output.write ((byte) r);
            }
        } Catch (Exception e) {
            e.printStackTrace ();
        } Finally {
            try {
                input.close ();
                output.close ();
            } Catch (IOException e) {
                e.printStackTrace ();
            }
        }
        
    }
    public static void copy2 (String src, String tar) {
        InputStream input = null;
        OutputStream output = null;
        try {
            input = new FileInputStream (src);
            output = new FileOutputStream (tar);
            int length = 0;
            byte [] b = new byte [1024];
            while ((length = input.read (b)) = -! 1) {
                output.write (b, 0, length);
            }
        } Catch (Exception e) {
            e.printStackTrace ();
        } Finally {
            try {
                input.close ();
                output.close ();
            } Catch (IOException e) {
                e.printStackTrace ();
            }
        }
    }
    
    public static void copy3 (String src, String tar) {
        InputStream input = null;
        OutputStream output = null;
        try {
            input = new DataInputStream (new BufferedInputStream (new FileInputStream (src)));
            output = new DataOutputStream (new BufferedOutputStream (new FileOutputStream (tar)));
            / *** Passes pro-test, buffer buffered stream read indeed faster **** /
            
            int length = 0;
            byte [] b = new byte [1024]; // read the first stream into the byte array
            while ((length = input.read (b)) = -! 1) {
                output.write (b, 0, length);
            }
        } Catch (Exception e) {
            e.printStackTrace ();
        } Finally {
            try {
                input.close ();
                output.close ();
            } Catch (IOException e) {
                e.printStackTrace ();
            }
        }
    }
}
     
         
         
         
  More:      
 
- Xshell configure SSH free password (Server)
- Netfilter / Iptables Comments (Linux)
- XenServer virtual machines installed in dual-card configuration (Server)
- ORA-01839 error caused by incorrect system date setting (Database)
- Linux environment Duplex (multi-machine) automatic mutual backup scheme (Linux)
- AFNetworking + Nginx HTTPS communication server + (Server)
- Hanoi problem Java Solution (Programming)
- Manual cleaning Oracle audit records (Database)
- ssh port forwarding Comments (Server)
- Java NIO The Glob mode Detailed (Programming)
- tcpdump Linux system security tools (Linux)
- Hadoop 1 and 2.x installation notes (Server)
- CentOS 6.5 installation and deployment SVN 1.8.10 (Linux)
- DELL D630 Wireless LAN Driver Installation CentOS6 (Linux)
- Zookeeper Rights Management and Quota Management (Server)
- Node.js v4.0.0 installation configuration on Ubuntu 14.04 / 15.04 (Linux)
- xCAT Installation Kit (Linux)
- Intel Graphics Installer 1.0.3 released, support for Ubuntu (Linux)
- Try the command ip, ifconfig is obsolete under Linux (Linux)
- Use Aptik Battery Monitor monitoring Ubuntu laptop battery usage (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.