arraylist
이 String[]
으로 가득한 FileOutputStream을 xml 파일에 저장했습니다. 문제는 파일을로드 할 때 String으로만로드 할 수 있다는 것입니다. 문자열이 좀 이상한 코드입니다 추천했습니다 : I가 도움을 필요로XML 파일을 읽을 때 Java 오류가 발생했습니다.
[Ljava.lang.String;@75a7d0f4
, 부하 방법에 내가 통과해야, 저장 (또는로드)를 String[]
년대 그래서 아마
그들을 호출 할 수 있습니다 그리고 모든 데이터는 루프가있는 addSong()
메서드에 있습니까?
코드 :
public class Songs {
List<String[]> songs = new ArrayList<String[]>();
public void addSong(String s, String a, String yt){
String[] songarray= new String[3];
songarray[0] = s;
songarray[1] = a;
songarray[2] = yt;
songs.add(songarray);
}
public void editSong(int i, String s, String a, String yt){
String[] editsongarray = new String[3];
editsongarray[0] = s;
editsongarray[1] = a;
editsongarray[2] = yt;
songs.remove(i);
songs.add(i,editsongarray);
}
public void removeSong(int i){
songs.remove(i);
}
public String[] getList(int i){
String[] j = songs.get(i);
return j;
}
public void save() throws FileNotFoundException{
PrintWriter pw = new PrintWriter(new FileOutputStream("C:\\Applications\\songs.xml"));
for(String[] x:songs)
pw.println(x);
pw.close();
}
public void load()throws FileNotFoundException{
FileInputStream in = new FileInputStream("C:\\Applications\\songs.xml");
Scanner scan = new Scanner(in);
String x = scan.next();
//String[] x = scan.next(); doesnt works
System.out.println(x);
}
} 당신이 배열을 인쇄 할 때 기본 출력의
나를 오해 할 수 있습니다. 그러나 내로드 메서드에서 XML 파일을 Strings로드합니다. 문제는 꽤 String 배열 (String []), 변환 또는 배열 (String []) 같이 XML 파일로드 할 필요가 있습니다. Array.toString(), wouldt는 String에서 작동합니다. 그렇습니까 ?? 덕분에, 고맙습니다 :-) –
xml은 dom4j (가장 쉬운) 또는 stax (정말 큰 xml 문서는 더 복잡하지만 더 복잡함)와 같은 구문을 사용하려는 경우, – evanchooly