Last active
August 22, 2018 02:53
-
-
Save modeverv/c976ae96ce9f00174eb780f590566b2c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package norainu; | |
import java.io.FileInputStream; | |
import java.io.FileOutputStream; | |
import java.io.InputStreamReader; | |
import java.io.OutputStreamWriter; | |
// AutoClosable | |
public class Main { | |
public int b; | |
public static void main(String[] args) { | |
try (ACTest a = new ACTest()) { | |
a.methodA(); | |
} | |
try (FileInputStream is2 = new FileInputStream("C:/tmp/a.txt"); FileOutputStream os2 = new FileOutputStream("C:/tmp/a2.txt")) { | |
InputStreamReader ir2 = new InputStreamReader(is2, "UTF-8"); | |
OutputStreamWriter ow2 = new OutputStreamWriter(os2, "UTF-8"); | |
int tmp; | |
while ((tmp = ir2.read()) != -1) { | |
ow2.write(tmp); | |
} | |
ow2.flush(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
class ACTest implements AutoCloseable { | |
@Override | |
public void close() { | |
System.out.println("autoclosable"); | |
} | |
public void methodA() { | |
System.out.println("methodA"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment