Skip to content

Commit 4250ddd

Browse files
Java Codes
1 parent c862d6e commit 4250ddd

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

FileIo.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import java.io.FileInputStream;
2+
import java.io.FileNotFoundException;
3+
import java.io.IOException;
4+
5+
public class FileIo {
6+
public static void main(String[] args) {
7+
try {
8+
FileInputStream obj=new FileInputStream("demo.txt");
9+
int i= obj.read();
10+
System.out.println((char)i);
11+
} catch (Exception e) {
12+
13+
e.printStackTrace();
14+
}
15+
}
16+
17+
18+
}

FileIo1.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import java.io.FileInputStream;
2+
import java.io.FileNotFoundException;
3+
4+
public class FileIo1 {
5+
public static void main(String[] args) {
6+
try {
7+
FileInputStream pbj=new FileInputStream("demo.txt");
8+
int i=0;
9+
while ((i=pbj.read())!=-1) {
10+
System.out.print((char)i);
11+
12+
}
13+
pbj.close();
14+
} catch (Exception e) {
15+
16+
e.printStackTrace();
17+
}
18+
19+
20+
21+
}
22+
23+
}

FileOut.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.io.BufferedOutputStream;
2+
import java.io.FileNotFoundException;
3+
import java.io.FileOutputStream;
4+
5+
public class FileOut {
6+
public static void main(String[] args) {
7+
try {
8+
FileOutputStream obj=new FileOutputStream("demo.txt");
9+
BufferedOutputStream bos=new BufferedOutputStream(obj);
10+
String s="Saud ahmed kadapa Cdac";
11+
byte b[]=s.getBytes();
12+
bos.write(b);
13+
bos.flush();
14+
bos.close();
15+
obj.close();
16+
17+
18+
19+
20+
} catch (Exception e) {
21+
22+
e.printStackTrace();
23+
}
24+
25+
}
26+
27+
}

Hashmap.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import java.util.HashMap;
2+
import java.util.Map;
3+
4+
public class Hashmap {
5+
public static void main(String[] args) {
6+
Map<Integer,String>obj=new HashMap<>();
7+
obj.put(45, "Saud");
8+
obj.put(55, "Ahmed");
9+
System.out.println(obj.containsKey(65));
10+
System.out.println(obj);
11+
}
12+
13+
}

0 commit comments

Comments
 (0)