-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprogram1.java
More file actions
153 lines (119 loc) · 3.43 KB
/
Copy pathprogram1.java
File metadata and controls
153 lines (119 loc) · 3.43 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package com.testyantra.assign;
import java.io.*;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
public class Mainclass2
{
public static void main(String[] args) throws IOException
{
/*
String path= "//E://Demo//file_diff.txt";
File f=new File(path);
FileReader fr=new FileReader(f);
StringBuffer sb1=new StringBuffer();
StringBuffer sb2=new StringBuffer();
String data="";
long len=f.length();
for(int i=1;i<=len;i++)
{
int i1=fr.read();
char c1=(char)i1;
sb1=sb1.append(c1);
}
data=sb1.toString();
if(data.charAt(0)=='M' || data.charAt(0)=='A')
{
for(int i=data.length()-1;i>=0 && data.charAt(i)!='/';i--)
{
char ch=data.charAt(i);
sb2=sb2.append(ch);
}
}
sb2.reverse();
System.out.println(sb2);
fr.close();
*/
/*
try
{
//the file to be opened for reading
FileInputStream fis=new FileInputStream("//E://Demo//file_diff.txt");
Scanner sc=new Scanner(fis); //file to be scanned
//returns true if there is another line to read
while(sc.hasNextLine())
{
System.out.println(sc.nextLine());
//returns the line that was skipped
}
sc.close(); //closes the scanner
}
catch(IOException e)
{
e.printStackTrace();
}
*/
/* FileInputStream fstream = new FileInputStream("//E://Demo//file_diff.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null)
{
// Print the content on the console
System.out.println (strLine);
}
//Close the input stream
fstream.close();
*/
try
{
BufferedReader reader = new BufferedReader(new FileReader("//E://Demo//file_diff.txt"));
String line = reader.readLine();
while(line!=null)
{
System.out.println(line);
String str=line;
if(str.charAt(0)=='M'||str.charAt(0)=='A')
{
StringBuffer sb2=new StringBuffer();
for(int i=str.length()-1;i>=0 && str.charAt(i)!='/';i--)
{
char ch=str.charAt(i);
sb2.append(ch);
}
sb2.reverse();
String ss=str.charAt(0)+" "+sb2.toString()+" ";
File f=new File("//E://Demo//deployPackage//added.txt");
FileWriter fw=new FileWriter(f,true); //to write a data acts as connection between file and java code
fw.write(ss); //data will be stored to temporary data Fileoutputstream.
fw.flush(); //from Fileoutputstream it will flush data to file.
fw.close();
//System.out.println(sb2);
}
else if(str.charAt(0)=='R'||str.charAt(0)=='D')
{
StringBuffer sb2=new StringBuffer();
for(int i=str.length()-1;i>=0 && str.charAt(i)!='/';i--)
{
char ch=str.charAt(i);
sb2.append(ch);
}
sb2.reverse();
String ss=str.charAt(0)+" "+sb2.toString()+" ";
File f=new File("//E://Demo//deployPackage//removed.txt");
FileWriter fw=new FileWriter(f,true); //to write a data acts as connection between file and java code
fw.write(ss); //data will be stored to temporary data Fileoutputstream.
fw.flush(); //from Fileoutputstream it will flush data to file.
fw.close();
//System.out.println(sb2);
}
line = reader.readLine();
}
reader.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}