Commit a1d8aadc authored by chris.crook's avatar chris.crook

> adding load / save

parent 590901d0
......@@ -12,16 +12,37 @@ import java.io.FileWriter;
import java.util.Scanner;
public class MainActivity extends AppCompatActivity {
// file info and load
String filename1 = "magicwords";
String filename2 = "appdatatxt";
File file1;
File file2;
// generic variables and stuff
int sizeoverride = 1000;
String tempload = "";
String [] [] magicwords = new String [sizeoverride] [5]; // storage of the login info
int size = 0;
boolean tempbool = true;
int tempint = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
file1 = new File(getApplicationContext().getFilesDir(), filename1 + ".txt");
file2 = new File(getApplicationContext().getFilesDir(), filename2 + ".txt");
for (int i = 0; i < sizeoverride; i ++){
magicwords [i] [0] = "END";
}
try{
FileWriter stream = new FileWriter(file1, true);
stream.append(""); //opens and test-loads an append
stream.close();
} catch(Exception e){
Toast.makeText(getApplicationContext(), "write error", Toast.LENGTH_SHORT).show();
}
try{
Scanner reader = new Scanner(file1);
String temp = "";
......@@ -29,36 +50,65 @@ public class MainActivity extends AppCompatActivity {
while (reader.hasNextLine()){
temp = temp + reader.nextLine();
}
Toast.makeText(getApplicationContext(), temp + " ", Toast.LENGTH_LONG).show();
} catch(Exception e){
Toast.makeText(getApplicationContext(), "read error", Toast.LENGTH_LONG).show();
try{
FileWriter stream = new FileWriter(file1, false);
stream.write(" ");
stream.close();
} catch(Exception e){
Toast.makeText(getApplicationContext(), "write error", Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "read error", Toast.LENGTH_SHORT).show();
}
tempload = openandload();
if (tempload.equals("&&&")){
// this means that the load failed
}
else{
// load successful
if (tempload.equals("")){
// dont add a '#' to the start
}
else{
tempload += "#";
}
tempload += "adminname&adminuser&adminpassword&ADMIN";
String [] temploadarray = tempload.split("%");
size = temploadarray.length;
for (int i = 0; i < size; i++){
magicwords [i] [0] = temploadarray [i]; // splits by user
}
for (int i = 0; i < size; i++){
String [] sort = temploadarray [i].split("&");
magicwords [i] [1] = sort [0];
magicwords [i] [2] = sort [1];
magicwords [i] [3] = sort [2];
magicwords [i] [4] = sort [3];
}
/*for (int i = 0; i < sizeoverride; i++){
if (magicwords [i] [0].equals("END")){
// end marker found
tempint = i;
break;
}
System.out.println(size + "");
System.out.println(tempint + "");
}*/
}
}
public void openandload(View view){
public String openandload(){
try{
Scanner reader = new Scanner(file1);
String temp = "";
while (reader.hasNextLine()){
temp = temp + reader.nextLine();
}
Toast.makeText(getApplicationContext(), temp + " ", Toast.LENGTH_LONG).show();
return temp;
} catch(Exception e){
Toast.makeText(getApplicationContext(), "read error", Toast.LENGTH_LONG).show();
return "&&&";
}
}
public void saveandclose(View view){
public void saveandclose(){
try{
FileWriter stream = new FileWriter(file1, false);
stream.write(" ");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment