Skip to content

Commit

Permalink
11b - IO classes
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioBenov committed Nov 11, 2024
1 parent 0a89444 commit cface42
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 0 deletions.
29 changes: 29 additions & 0 deletions materials/2024-2025/11b/2024-11-11-io/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
3 changes: 3 additions & 0 deletions materials/2024-2025/11b/2024-11-11-io/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions materials/2024-2025/11b/2024-11-11-io/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions materials/2024-2025/11b/2024-11-11-io/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions materials/2024-2025/11b/2024-11-11-io/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions materials/2024-2025/11b/2024-11-11-io/2024-11-11-io.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?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>
105 changes: 105 additions & 0 deletions materials/2024-2025/11b/2024-11-11-io/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import java.io.*;
import java.nio.file.Paths;
import java.util.Scanner;

public class Main {
public static class MyException extends Exception {
public MyException(String arg) {
super(arg);
}
};

static void foo(Object arg) throws FileNotFoundException, MyException {
// try {
if (arg == null)
throw new MyException("Invalid argument");

throw new FileNotFoundException();
// do some work
// } catch (FileNotFoundException e) {
// throw new RuntimeException(e);
// }
}

static void bar() throws MyException {
System.out.println("Hello world!");

try {
foo(null);
} catch (FileNotFoundException e) {
// System.out.println(e.getStackTrace());
e.printStackTrace();
} catch (MyException e) {
// System.out.println(e.getStackTrace());
e.printStackTrace();
// return;
throw e;
} finally {
System.out.println("In main finally");
}

System.out.println("AFter catch");
}

static void baz() {
// InputStream is = new BufferedInputStream(System.in);
// BufferedInputStream is = new BufferedInputStream(System.in);
// DataInputStream dis = new DataInputStream(is);

// try {
// int c;
// while((c = is.read()) != -1) {
// System.out.println(c);
// }
// } catch (IOException e) {
// System.out.printf("Failed to read");
// System.out.printf(e.getMessage());
// }

// try {
// int a = dis.readInt();
// String b = dis.readLine();
// System.out.println(a);
// System.out.println(b);
// } catch (IOException e) {
// System.out.printf("Failed to read");
// System.out.printf(e.getMessage());
// }
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in)
);
try {
System.out.println(br.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}

Scanner sc = new Scanner(
new BufferedInputStream(System.in)
);
while(sc.hasNextLine()) {
sc.nextLine();
}

try {
Scanner fsc = new Scanner(
// new FileInputStream("./in.txt")
// new BufferedInputStream(
// new FileInputStream("./in.txt")
// )
// "./in.txt"
Paths.get("./in.txt")
);

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public static void main(String[] args) throws MyException {
// bar();
baz();
}
}

0 comments on commit cface42

Please sign in to comment.