package com.company; import java.io.File; import java.io.FileWriter; import java.util.ArrayList; import java.util.Formatter; import java.util.Scanner; public class ReadGraph { public Graph readOfFile(){ File fIn = new File("In0205.txt"); File fInP = new File("In0205P.txt"); Graph graph = null; if(!fIn.exists()){ try{ fIn.createNewFile(); }catch (Exception e){ System.out.println(e.getMessage()); } } if(!fInP.exists()){ try{ fInP.createNewFile(); }catch (Exception e){ System.out.println(e.getMessage()); } } if(fIn.canRead()){ try{ Scanner scFIn = new Scanner(fIn); int licznik = -1; int ilosc = 0; while(scFIn.hasNextLine()){ Pomocniczy(scFIn.nextLine()); Scanner scFInP = new Scanner(fInP); if(licznik == -1){ licznik++; ilosc = scFInP.nextInt(); graph = new Graph(ilosc); } else{ while (scFInP.hasNext()){ graph.addEdge(licznik,(scFInP.nextInt()-1)); } licznik++; } scFInP.close(); } scFIn.close(); }catch (Exception e){ System.out.println(e.getMessage()); } } return graph; } protected void Pomocniczy(String linia){ try{ File fInP = new File("In0205P.txt"); FileWriter fw = new FileWriter(fInP, false); Formatter formatter = new Formatter(fw); formatter.format("%s",linia); formatter.close(); fw.close(); }catch (Exception e){ System.out.println(e.getMessage()); } } }