Double Linked 데이터 구조에서 파일로 데이터를 쓰려고 시도하지만 Printwriter try catch 블록 내에서 데이터를 인쇄하는 방법을 찾을 수 없습니다.파일에 액세스하고 데이터 구조 데이터를 try try에서 액세스 할 수 없음 catch printWriter
public static void main(String[] args) {
/* Start with the empty list */
LinkedList lk = new LinkedList();
Order x = new Order("1", "x", 1);
Order y = new Order("2", "y", 1);
DoubleNode dll = new DoubleNode();
File f = new File("/Users/Dell/Documents/product.txt");
Product a = new Product("1", "a", 1, 1, 1.);
Product b = new Product("2", "b", 2, 2, 2.);
Product c = new Product("3", "c", 3, 3, 3.);
Product d = new Product("4", "d", 4, 4, 4.);
Product e = new Product("5", "e", 5, 5, 5.);
dll.append(b);
dll.push(d);
dll.push(a);
dll.append(c);
dll.InsertAfter(dll.head.next, e);
System.out.println("Created DLL is: ");
dll.printlistF(dll.head);
String filePath;
try {
f.createNewFile();
filePath = f.getCanonicalPath();
}
catch(IOException io) {
io.printStackTrace();
}
if (f.exists()) {
System.out.println("File exist.");
System.out.println("File is readable: " + f.canRead());
System.out.println("File is writeable: " + f.canWrite());
System.out.println("File is location: " + f.getName());
}
try {
PrintWriter output = new PrintWriter(f);
dll.printlistF(dll.head); //THIS IS THE PLACE I CANT FIGURE IT OUT
output.close();
} catch (IOException e2) {
// TODO: handle exception
System.out.println("ERROR"+e2);
}
}
하지만이 시도의 catch 블록 내부에 새로운 DoubleNode을 만들기 위해 나를 필요로하고 내가 DLL 정적 만들려고 할 때, 그것은 "불법 수정이 만 마지막이 허용된다"고 말했다. 그래서 내가 무엇을해야하니? 나는 여기서 비슷한 주제를 찾기 위해 프로그래밍 용어에 대해 충분히 알지 못한다. 그래서 누군가가 그들에 대한 링크를 가지고 있다면 그것은 높이 평가 될 것이다.
정적 멤버는 해당 클래스의 특정 인스턴스가 아닌 클래스 자체에 속하게됩니다.메서드 내에서 static 키워드 수정자를 사용할 수 없습니다. 현재 해당 인스턴스 내에 있습니다. 변수를 정적으로 만들려면 클래스 수준에서 변수를 선언해야합니다. – Zachary
당신은 단지 쓰기를 위해 파일을 열고 ('new PrintWriter (f)') 로컬 변수'output'에 할당 했으므로,'printlistF' 메쏘드가 데이터 구조체를 작성하는데 사용되었다고 생각할지도 모른다. * 그 값, 즉'output' 값?!?!? 예 : 'dll.printlistF (output);','dll.head' 매개 변수가 필요 없기 때문에. – Andreas