import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.OutputStreamWriter;public class Test { public static void main(String[] args) throws Exception { String s = "Hello World"; char[] c = s.toCharArray(); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter( new FileOutputStream("D:\\d.txt")));
bw.write(c);
bw.close(); } }
自己写了一下 fw = new FileWriter(fileName); bw = new BufferedWriter(fw); String s =this.ja.getText(); char []c = new char[1024]; int len = s.length(); //余数 int yu = len%1024; //商 int shang = (yu==0)?(len/1024):(len/1024+1); System.out.println(shang);
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;public class Test
{
public static void main(String[] args) throws Exception
{
String s = "Hello World"; char[] c = s.toCharArray(); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("D:\\d.txt")));
bw.write(c);
bw.close();
}
}
fw = new FileWriter(fileName);
bw = new BufferedWriter(fw);
String s =this.ja.getText();
char []c = new char[1024];
int len = s.length();
//余数
int yu = len%1024;
//商
int shang = (yu==0)?(len/1024):(len/1024+1);
System.out.println(shang);
for(int i=0;i<shang;i++){
if(i<shang-1){
s.getChars(i*1024, (i+1)*1024, c, 0);
bw.write(c);
}else{
s.getChars(i*1024,i*1024+yu, c, 0);
bw.write(c, 0, yu);
}
}