- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWriter.java
More file actions
Latest commit
52 lines (48 loc) · 1.35 KB
/
Copy pathWriter.java
File metadata and controls
52 lines (48 loc) · 1.35 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
importjava.io.*;
/**
* The Write class, to write to files.
*
* @author Matthew Hillier
* @version 1.0
*/
publicclassWriter
{
/**
* Overwrites an old file with a new file.
* @param newFile The new file to write with.
* @param oldFile The old file to overwrite.
*/
publicstaticvoidoverwriteFile(StringnewFile, StringoldFile)
{
try
{
BufferedReaderreader = newBufferedReader(newFileReader(newFile + ".txt"));
Stringline = null;
StringBuilderstringBuilder = newStringBuilder();
Stringls = System.getProperty("line.separator");
FileWriterwriter = newFileWriter(oldFile + ".txt");
try
{
while((line = reader.readLine()) != null)
{
stringBuilder.append(line);
stringBuilder.append(ls);
}
writer.write(stringBuilder.toString());
}
catch(IOExceptione)
{
e.printStackTrace();
}
finally
{
reader.close();
writer.close();
}
}
catch(Exceptionerror)
{
System.out.println(error.getMessage());
}
}
}