arrayList를 읽고이 문자열을 파일에 저장하려고합니다. 이 몇 가지 코드 나는이된다arrayList를 읽고이를 파일에 저장하십시오. Java
output = new Formatter(nameFile + ".txt");
while (textLines.hasNext()){
output.format(nameFile, textLines);
}
arrayList를 읽고이 문자열을 파일에 저장하려고합니다. 이 몇 가지 코드 나는이된다arrayList를 읽고이를 파일에 저장하십시오. Java
output = new Formatter(nameFile + ".txt");
while (textLines.hasNext()){
output.format(nameFile, textLines);
}
public class test1 {
public static void main(String args[]) throws IOException{
StringBuffer sb = new StringBuffer();
String filepath = "test.txt";
List<String> list = new ArrayList<String>();
list.add("1");
list.add("2");
list.add("3");
list.add("4");
list.add("5");
list.add("6");
Iterator<String> it = list.iterator();
while(it.hasNext())
{
sb.append(it.next());
sb.append(",");
}
BufferedWriter bw = new BufferedWriter(new FileWriter(filepath));
bw.write(sb.toString());
bw.flush();
bw.close();
}
}
이는 * 문제가 무엇
PrintWriter writer = new PrintWriter("file-name.txt");
for(String s:yourList) //iterate your ArrayList here
{
writer.println(s);
}
writer.close();
@ user3649644 당신을 위해 효과가있는 경우 대답을 선택하십시오. – Abhishek
시도 *? –
예상대로 작동하거나 작동하지 않는 것은 무엇입니까? – EWit
질문이 있으시거나 귀하의 작업을 우리에게 보여주는 것입니다. –