Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.Formatter;
- import java.util.Properties;
- import java.util.Scanner;
- import javax.swing.JFrame;
- public class main{
- public static void main(String args[]) throws InterruptedException {
- @SuppressWarnings("unused")
- JFrame frame = new frame();
- File a= new File(args[0]);
- System.out.println(a.getName());
- createdata();
- }
- private static String benutzer = new Properties(System.getProperties()).getProperty("user.name");
- private static String datapath = "C://Users/"+benutzer+"/Documents/"+benutzer+"_WurzelZieher";
- private static String filename = "BenchmarkPoins.txt";
- public static void createdata(){
- File file = new File(datapath+"/"+filename);
- File dir = new File(datapath);
- if(!dir.exists()){
- dir.mkdirs();
- }
- if(!file.exists()){
- try {
- file.createNewFile();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }else{
- }
- }
- @SuppressWarnings("resource")
- public static void addData(int value){
- if(value==0){
- return;
- }
- Formatter x = null;
- ArrayList<Integer> re = null;
- re = new ArrayList<Integer>();
- Scanner s = null;
- File file = new File(datapath+"/"+filename);
- if(!file.exists()){
- createdata();
- }
- try {
- s=new Scanner(file);
- } catch (FileNotFoundException e) {
- return;
- }
- if(!s.hasNext()){
- try {
- x = new Formatter(file);
- x.format("%s ",value);
- x.close();
- } catch (FileNotFoundException e) {
- }
- return;
- }
- boolean run = true;
- while(run){
- if(s.hasNext()){
- re.add(s.nextInt());
- }else{
- run = false;
- }
- }
- re.add(value);
- try {
- x = new Formatter(file);
- } catch (FileNotFoundException e) {
- return;
- }
- for(int i = 0;i<re.size();i++){
- x.format("%s ",re.get(i));
- }
- x.close();
- return;
- }
- @SuppressWarnings("resource")
- public static ArrayList<Integer> getData(){
- ArrayList<Integer> re = null;
- re = new ArrayList<Integer>();
- Scanner s = null;
- File file = new File(datapath+"/"+filename);
- if(!file.exists()){
- return null;
- }
- if(!file.exists()){
- return null;
- }
- try {
- s=new Scanner(file);
- } catch (FileNotFoundException e) {
- return null;
- }
- if(!s.hasNext()){
- re.add(0);
- return re;
- }
- boolean run = true;
- while(run){
- if(s.hasNext()){
- re.add(s.nextInt());
- }else{
- run = false;
- }
- }
- return re;
- }
- public static void removeData(){
- Formatter x = null;
- File file = new File(datapath+"/"+filename);
- if(!file.exists()){
- return;
- }
- try {
- x = new Formatter(file);
- x.format("","");
- x.close();
- } catch (FileNotFoundException e) {
- return;
- }
- return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement