Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Java to achieve local fileCopy     - Linux system using the command line shutdown or restart (Linux)

- Java gets the current system time System.currentTimeMillis () (Programming)

- The Definitive Guide to Linux NAT network connection (Linux)

- Ambari and Hadoop configuration, management and monitoring of the project Getting (Server)

- Variables Python variables (Programming)

- MySQL database under Linux to achieve automatic backup scheduled backup day (Database)

- Use Mop monitor stock prices at the Linux command line (Linux)

- Object Oriented Programming Java reflection (Programming)

- Ubuntu users to install the system indicator SysPeek 0.3 (Linux)

- Bash variable expansion modifier (Programming)

- How to enable Software Collections (SCL) on CentOS (Server)

- SecureCRT remote connection Ubuntu fails to solve the case (Linux)

- Installation and use the telnet command under CentOS 6.x (Linux)

- ActiveMQ5.11.1 and JDK version matching relation (Linux)

- Linux static library generated Guide (Programming)

- Build Python3.4 + PyQt5.3.2 + Eric 6.0 development platform Ubuntu 14.04 (Server)

- How to update the Linux kernel to improve system performance (Linux)

- How do you prevent other users from accessing your home directory in Linux (Linux)

- Installation and deployment of Hadoop 2.7.1 on Ubuntu 14.04 LTS (Server)

- Node.js v4.0.0 installation configuration on Ubuntu 14.04 / 15.04 (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:      
 
- Docker manage data (Linux)
- Linux ldconfig command (Linux)
- Expand an existing RAID arrays and remove the failed disk in a RAID (Linux)
- Ubuntu installation 2.10.x version of Scala (Linux)
- Using LLVM Clang and Blocks under Linux (Programming)
- The difference between Objective-C language nil, Nil, NULL, NSNull (Programming)
- Service Discovery: Zookeeper vs etcd vs Consul (Server)
- To install the Oracle 10.2.0.1.0 process notes on Oracle Linux 4u4 (Database)
- Linux SU command security Suggestions (Linux)
- Linux set to select the appropriate level of security of the network according to deployment (Linux)
- Ubuntu 13.04 configure MyEclipse 10.7 Environment (Linux)
- Ubuntu 12.04 installation NVIDIA GTX750 graphics driver (Linux)
- Linux, Apache Web site security settings (Linux)
- RHEL7 unattended automatic installation DHCP + TFTP + SYSLINUX + TFTP + Kickstart (Linux)
- To install the Contiki development toolchain on Ubuntu (Linux)
- Android Studio commonly used shortcuts and how to follow the Eclipse Shortcuts (Linux)
- Experience CoreCLR stack unwinding characteristics of initial implementation on Linux / Mac (Linux)
- To build Spring RestTemplate use HttpClient4 (Programming)
- According to the national position on how to block traffic in Linux (Server)
- Linux package management operations Basic entry (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.