File tree Expand file tree Collapse file tree 9 files changed +116
-0
lines changed
Expand file tree Collapse file tree 9 files changed +116
-0
lines changed Original file line number Diff line number Diff line change 1+ sushma
2+ 100
3+ you caan read this
4+ Only you can read this girl
5+ hey how are you
6+ this will be last line
7+ -----------------------------------
Original file line number Diff line number Diff line change 1+ /**
2+ *
3+ */
4+ /**
5+ *
6+ */
7+ module tryCatch {
8+ }
Original file line number Diff line number Diff line change 1+ package tryCatch ;
2+ import java .io .File ;
3+ import java .io .IOException ;
4+ import java .io .PrintWriter ;
5+
6+ public class CreateFile {
7+
8+ public static void main (String [] args ) throws IOException {
9+ // TODO Auto-generated method stub
10+
11+ try {
12+ File f = new File ("myfile.txt" );
13+ System .out .println ("This is the text Flie" );
14+
15+
16+ if (!f .exists ()) {
17+ f .createNewFile ();
18+ }
19+
20+ PrintWriter pw = new PrintWriter (f );
21+ pw .println ("sushma" );
22+ pw .println (100 );
23+ pw .println ("you caan read this" );
24+ pw .println ("Only you can read this girl" );
25+ pw .println ("hey how are you" );
26+ pw .println ("this will be last line" );
27+ pw .println ("-----------------------------------" );
28+ pw .close ();
29+ }
30+ catch (IOException e ) {
31+ e .printStackTrace ();
32+
33+ }
34+ System .out .println ("done" );
35+ }
36+
37+
38+ }
Original file line number Diff line number Diff line change 1+ package tryCatch ;
2+
3+ public class Finally {
4+
5+ public static int funInt () {
6+ int a = 1000 ;
7+ try {
8+ a = a /00 ;
9+ return a ;
10+
11+ } catch (ArithmeticException e ) {
12+ System .out .println (e );
13+ System .out .println ("this is catch method" );
14+ return a ;
15+
16+ } finally {
17+ a = 5000 ;
18+ System .out .println ("This is finally" );
19+ return a ;
20+ }
21+ }
22+
23+
24+ public static void main (String [] args ) {
25+ System .out .println (funInt ());
26+ }
27+ }
Original file line number Diff line number Diff line change 1+ package tryCatch ;
2+
3+ import java .io .BufferedReader ;
4+ import java .io .FileReader ;
5+ import java .io .IOException ;
6+
7+ public class fliereader {
8+
9+ public static void main (String [] args ) {
10+ // TODO Auto-generated method stub
11+ BufferedReader br = null ;
12+
13+ try {
14+ br = new BufferedReader (new FileReader ("myfile.txt" ));
15+ String line ;
16+
17+ while ((line = br .readLine ()) != null ) {
18+ System .out .println (line );
19+ }
20+
21+ }catch (Exception e ) {
22+ e .printStackTrace ();
23+
24+ } finally {
25+ try {
26+ br .close ();
27+ } catch (IOException e ) {
28+ e .printStackTrace ();
29+ }
30+
31+ System .out .println ("The End" );
32+ }
33+
34+ }
35+
36+ }
You can’t perform that action at this time.
0 commit comments