Skip to content

Instantly share code, notes, and snippets.

@modeverv
Last active August 22, 2018 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save modeverv/c976ae96ce9f00174eb780f590566b2c to your computer and use it in GitHub Desktop.
Save modeverv/c976ae96ce9f00174eb780f590566b2c to your computer and use it in GitHub Desktop.
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