-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain_class.java
More file actions
executable file
·72 lines (70 loc) · 1.64 KB
/
main_class.java
File metadata and controls
executable file
·72 lines (70 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import java.io.*;
class file{
private File f=null;
private FileInputStream fis=null;
private FileOutputStream fos=null;
private DataInputStream dis=null;
private DataOutputStream dos=null;
private InputStream is=null;
private OutputStream os=null;
file(String filename){
try{
f=new java.io.File(filename);
if(!f.exists()){
f.createNewFile();
}
fis=new FileInputStream(f);
fos=new FileOutputStream(f);
dis=new DataInputStream(fis);
dos=new DataOutputStream(fos);
is=(InputStream)fis;
os=(OutputStream)fos;
}
catch(Exception e){
System.out.println("Error in open file "+e.getMessage());
}
}
public boolean write(String s) throws IOException{
boolean result=false;
if(dos!=null){
dos.writeUTF(s);
os.write(("\n"+s).getBytes());
dos.flush();
System.out.println("Writeln into file");
result=true;
}
else {
System.out.println("Error in write to file");
result=false;
}
return result;
}
public String read() throws IOException{
String result="";
byte[] buffer=new byte[255];
int read_count=0;
if(dis.markSupported()){
dis.reset();
}
//dis.reset();
//is.reset();
//fis.reset();
while((read_count=dis.read(buffer))!=-1){
result=result+(new String(buffer,0,read_count));
}
return result;
}
}
public class main_class {
public static void main(String args[]){
try{
file f=new file("c://1.txt");
f.write("hello");
System.out.println("read_form_file:"+f.read());
}
catch(Exception e){
System.out.println("Error in work with file\n"+e.getMessage());
}
System.out.println("OK");
}
}