FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
code-backup/5th_sem_C_Java_VB/Java/File_Handling/q5.java at master · Jimut123/code-backup · GitHub
This repository was archived by the owner on Jul 28, 2024. It is now read-only.
Jimut123
/
code-backup
Public archive
Notifications
You must be signed in to change notification settings
Fork
6
Star
20
Code
Issues
0
Pull requests
35
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
code-backup
/
5th_sem_C_Java_VB
/
Java
/
File_Handling
/
q5.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
147 lines (75 loc) · 2.35 KB
Breadcrumbs
code-backup
/
5th_sem_C_Java_VB
/
Java
/
File_Handling
/
q5.java
Copy path
File metadata and controls
147 lines (75 loc) · 2.35 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*Write a program to remove all comment lines from any Java source program.
The program should also display number of comment lines removed from a program.*/
import
java
.
io
.*;
class
q5
{
public
static
void
main
(
String
args
[])
throws
IOException
{
int
ch
,
ch1
,
ch2
,
ch3
;
long
nc
,
n
,
i
;
String
file1
,
file2
;
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
System
.
in
));
System
.
out
.
print
(
"
\n
Enter Input File Name = "
);
file1
=
br
.
readLine
();
System
.
out
.
print
(
"Enter Output File Name = "
);
file2
=
br
.
readLine
();
RandomAccessFile
fp1
=
new
RandomAccessFile
(
file1
,
"r"
);
FileOutputStream
fp2
=
new
FileOutputStream
(
file2
);
n
=
nc
=
0
;
//n=size of input file
while
((
ch
=
fp1
.
read
())!=-
1
)
{
n
++;
if
(
ch
==
34
)
{
do
{
fp2
.
write
(
ch
);
ch
=
fp1
.
read
();
n
++;
}
while
(
ch
!=
34
);
fp2
.
write
(
ch
);
}
else
if
((
char
)
ch
==
'/'
)
{
ch1
=
fp1
.
read
();
n
++;
if
((
char
)
ch1
==
'/'
)
{
nc
++;
do
{
ch1
=
fp1
.
read
();
n
++;
}
while
(
ch1
!=
10
);
}
else
if
((
char
)
ch1
==
'*'
)
{
/*To skip all
characters within
comment */
nc
++;
ch2
=
fp1
.
read
();
do
{
ch3
=
fp1
.
read
();
if
((
char
)
ch2
==
'*'
&& (
char
)
ch3
==
'/'
)
break
;
ch2
=
ch3
;
}
while
(
1
==
1
);
}
else
{
fp2
.
write
(
ch
);
fp2
.
write
(
ch1
);
}
}
else
fp2
.
write
(
ch
);
System
.
out
.
println
((
char
)
ch
);
}
fp1
.
close
();
fp2
.
close
();
System
.
out
.
println
(
"
\n
Number of Comment lines removed = "
+
nc
);
System
.
out
.
println
(
"
\n
//This is not a comment line"
);
}
}
Back
|
FazBrowse Home
|
New Git URL