-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFileWriter.java
More file actions
32 lines (30 loc) · 823 Bytes
/
FileWriter.java
File metadata and controls
32 lines (30 loc) · 823 Bytes
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
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
public class FileWriter
{
public String reader(String inputFile) throws IOException
{
File file = new File(inputFile);
StringBuilder str = new StringBuilder();
BufferedReader br = new BufferedReader(new FileReader(file));
while (br.ready())
{
str.append(br.read());
}
br.close();
return str.toString();
}
public void writer(String str) throws IOException
{
PrintWriter pw = new PrintWriter("fileOut.txt");
pw.println(str);
pw.close();
}
public int countCharacters (String fileName) throws IOException
{
return reader (fileName).length ();
}
}