日期:2014-05-20 浏览次数:21090 次
public class Txt {
public static void main(String[] args) {
String str="张三 0 3000 李四 1 5000 王五 0 4000";
String[] str1 = new String[10];
FileWriter writer;
int i=0;
int j=0;
while(i<=str.length()) {
str1[j] = str.substring(i, i+9);
i=i+10;
j=j+1;
}
try {
writer = new FileWriter("C:/Users/Administrator/Desktop/1.txt");
writer.write(str1[0]);
writer.write("\r\n");
writer.write(str1[1]);
writer.write("\r\n");
writer.write(str1[2]);
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
import java.io.FileWriter;
import java.io.IOException;
public class T1 {
public static void main(String[] args) {
String str="张三 0 3000\r李四 1 5000\r王五 0 4000";
FileWriter writer;
try {
writer = new FileWriter("/home/1.txt");
writer.write(str);
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}