Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Heres some good code that might be usefull to you:</p> <pre><code>public void writeToNewFile(String filePath, String data) { PrintWriter writer; File file; try { file = new File(filePath); file.createNewFile(); writer = new PrintWriter(new FileWriter(file)); writer.println(data); writer.flush(); writer.close(); }catch(Exception e){e.printStackTrace();} writer = null; file = null; \\setting file &amp; writer to null releases all the system resources and allows the files to be accessed again later } //this will write to end of file public void writeToExistingFile(String filePath, String data) { PrintWriter writer; File file; try { file = new File(filePath); if(!file.exists()) file.createNewFile(); writer = new PrintWriter(new FileWriter(file,true)); writer.println(data); writer.flush(); writer.close(); }catch(Exception e){e.printStackTrace();} writer = null; file = null; \\setting file &amp; writer to null releases all the system resources and allows the files to be accessed again later } public String[] readFile(String filePath) { String data[]; Iterator&lt;String&gt; it; ArrayList&lt;String&gt; dataHolder = new ArrayList&lt;String&gt;(); BufferedReader reader; File file; try { file = new File(filePath); reader = new BufferedReader(new FileReader(file)); int lines = 0; while(reader.ready()) { lines++; dataHolder.add(reader.readLine()); } data = new String[lines]; it = dataHolder.iterator(); for(int x=0;it.hasNext();x++) data[x] = it.next(); reader.close(); }catch(Exception e){e.printStackTrace();} reader = null; file = null; \\setting file &amp; reader to null releases all the system resources and allows the files to be accessed again later return data; } public void deleteFile(String filePath) { File file; try { file = new File(filePath); file.delete(); }catch(Exception e){e.printStackTrace();} file = null; } public void createDirectory(String directory) { File directory; try { directory = new File(directory); directoyr.mkDir(); }catch(Exception e){e.printStackTrace();} directory = null; } </code></pre> <p>Hope this helped!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload