몇 가지 결과가 있으며이를 ArrayList에 저장합니다. 나는 (출력) 이러한 txt 파일을 내 sdcard에 저장하고 싶습니다. 그러나 나는 모른다. 코드를 시도했지만 파일이 만들어지지 않았습니다. 파일이 만들어지면 다음 활동에 쓸 것입니다. 그리고 어떻게 ArrayList를 다음 Activity에 쓰는지 알고 싶습니다.내 ArrayList를 txt 파일에 쓰는 방법은 무엇입니까?
포인트 : 목록, 저장 Google지도 표시 자 위치 szoveg : String ArrayList.
if(points.size()>1 ) {
for(int i=0;i<points.size();i++){
for(int j=i+1;j<points.size();j++){
Location LocA = new Location("A");
LocA.setLatitude(points.get(i).latitude);
LocA.setLongitude(points.get(i).longitude);
Location LocB= new Location("B");
LocB.setLatitude(points.get(j).latitude);
LocB.setLongitude(points.get(j).longitude);
double distance = LocA.distanceTo(LocB);
String rad = "";
rad=sharedPreferences.getString("rad"+i, "0");
double radius=Double.parseDouble(rad);
String rad2 = "";
rad2=sharedPreferences.getString("rad"+j, "0");
double radius2=Double.parseDouble(rad2);
if(distance<radius && distance < radius2)
{
szoveg.add("Kommunikál: " +(i+1)+ " -> " +(j+1)+ " && " +(j+1)+ " -> " +(i+1)+ " - " + distance + " m");
Toast.makeText(getBaseContext(), "Kommunikál: " +(i+1)+ " -> " +(j+1)+ " && " +(j+1)+ " -> " +(i+1)+ " - " + distance + " m" , Toast.LENGTH_SHORT).show();
// Drawing Polyline on the map
//drawPolyline(point);
}
else if (distance>radius && distance<radius2)
{
szoveg.add("Kommunikál: " +(i+1)+ " -> " +(j+1)+ " && " +(j+1)+ " -> " +(i+1)+ " - " + distance + " m");
Toast.makeText(getBaseContext(), "Kommunikál: " + (j+1) + " -> " + (i+1)+ " - " + distance + " m" , Toast.LENGTH_SHORT).show();
// Drawing Polyline on the map
//drawPolyline(point);
}
else if (distance<radius && distance>radius2)
{
szoveg.add("Kommunikál: " +(i+1)+ " -> " +(j+1)+ " && " +(j+1)+ " -> " +(i+1)+ " - " + distance + " m");
Toast.makeText(getBaseContext(), "Kommunikál: " +(i+1)+ " -> " +(j+1)+ " - " + distance + " m" , Toast.LENGTH_SHORT).show();
// Drawing Polyline on the map
//drawPolyline(point);
}
//else Toast.makeText(getBaseContext(), "Nem kommunikál - " + distance + " m" , Toast.LENGTH_SHORT).show();
}
}
}
else Toast.makeText(getBaseContext(), "Marker is added to the Map", Toast.LENGTH_SHORT).show();
}
와 나는이 다른 응용 프로그램을 시도하지만 (나는에서 onCreate에서 writeTest()를 사용) 작동하지 않습니다
@SuppressLint("SdCardPath")
private void writeTest() {
lista = new ArrayList<String>();
int i= 0;
int j=0;
int distance = 100;
lista.add(("Kommunikál: " +(i+1)+ " -> " +(j+1)+ " && " +(j+1)+ " -> " +(i+1)+ " - " + distance + " m"));
lista.add("Kommunikál: " +(i+1)+ " -> " +(j+1)+ " && " +(j+1)+ " -> " +(i+1)+ " - " + distance + " m");
try {
FileOutputStream fileOut = new FileOutputStream("/mnt/sdcard/elso.txt");
ObjectOutputStream oos = new ObjectOutputStream (fileOut);
oos.writeObject(lista);
fileOut.close();
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
문제를 격리하고 긴 코드를 게시하는 대신 관련 코드 만 게시 할 수 있습니다. –