Skip to content

Instantly share code, notes, and snippets.

@Legion112
Created June 15, 2017 21:09
Show Gist options
  • Save Legion112/bfa76bc681d30ecdffc3aaf14f0073b0 to your computer and use it in GitHub Desktop.
Save Legion112/bfa76bc681d30ecdffc3aaf14f0073b0 to your computer and use it in GitHub Desktop.
LearnJava
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
package ru.fearofcode.learn.io;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
/**
* Created by maks on 6/16/2017.
*/
public class BufferedFileInput {
public static void main(String[] args) {
long timeStart = System.currentTimeMillis();
FileInputStream isFile = null;
BufferedInputStream buff = null;
try {
isFile = new FileInputStream(Settings.nameFile);
buff = new BufferedInputStream(isFile);
for (int i = 0; i < Settings.interactional; i++){
System.out.print(buff.read());
}
}catch(Exception e){
System.out.println("\nCould not read file: " + e.toString());
}finally{
try{
if (isFile != null) isFile.close();
if (buff != null) buff.close();
}catch(Exception e){
e.printStackTrace();
}
}
long timeFinish = System.currentTimeMillis();
System.out.println("\nTime of work " + BufferedFileInput.class + " " + (timeFinish - timeStart) / 1000 + " second");
}
}
package ru.fearofcode.learn.io;
import java.io.FileInputStream;
/**
* Created by maks on 6/16/2017.
*/
public class FileInput {
public static void main(String[] args) {
long timeStart = System.currentTimeMillis();
FileInputStream isFile = null;
try {
isFile = new FileInputStream(Settings.nameFile);
for (int i = 0; i < Settings.interactional; i++){
System.out.print(isFile.read());
}
}catch(Exception e){
System.out.println("\nCould not read in file: " + e.toString());
}finally{
try{
isFile.close();
}catch(Exception e){
e.printStackTrace();
}
}
long timeFinish = System.currentTimeMillis();
System.out.println("\nTime of work " + FileInput.class + " " + (timeFinish - timeStart) / 1000 + " second");
}
}
package ru.fearofcode.learn.io;
import java.io.FileOutputStream;
/**
* Created by maks on 6/16/2017.
*/
public class FileOutput {
public static void main(String[] args) {
long timeStart = System.currentTimeMillis();
FileOutputStream osFile = null;
try {
osFile = new FileOutputStream(Settings.nameFile);
for (int i = 0; i < Settings.interactional; i++){
osFile.write((int)(Math.random()*255));
}
}catch(Exception e){
System.out.println("Could not write to a file: " + e.toString());
}finally{
if (osFile != null)
try{
osFile.close();
}catch(Exception e){
e.printStackTrace();
}
}
long timeFinish = System.currentTimeMillis();
System.out.println("Time of work "+ FileOutput.class + " " + (timeFinish - timeStart) / 1000 + " second");
}
}
package ru.fearofcode.learn.io;
/**
* Created by maks on 6/16/2017.
*/
public class Settings {
static final int interactional = 20000000;
static final String nameFile = "file.txt";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment