-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWriteFile.java
More file actions
30 lines (24 loc) · 1.01 KB
/
WriteFile.java
File metadata and controls
30 lines (24 loc) · 1.01 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
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
public class WriteFile {
public static void writeFile(String url, String text, boolean withLineWrap){
try {
FileWriter fw = new FileWriter(url);
BufferedWriter bw = new BufferedWriter(fw);
char[] str = text.toCharArray();
for ( int i=0; i<str.length; i++ ) {
if ( withLineWrap && i%100==0 && i!=0 )
bw.append('\n');
bw.append(str[i]);
}
bw.close();
fw.close();
System.out.println("Writing file completed!");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}