forked from cSploit/android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileEdit.java
More file actions
111 lines (91 loc) · 3.21 KB
/
Copy pathFileEdit.java
File metadata and controls
111 lines (91 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package org.csploit.android.gui;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import org.csploit.android.R;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
public class FileEdit extends AppCompatActivity {
private Button mCmdSave = null;
private EditText mFileEditText = null;
public final static String KEY_FILEPATH = "FilePath";
private String mPath = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.file_edit);
setTitle("");
mCmdSave = (Button) findViewById(R.id.cmdSave);
mFileEditText = (EditText) findViewById(R.id.fileText);
mFileEditText.setHorizontallyScrolling(true);
if (getIntent() != null && getIntent().getExtras() != null && getIntent().getExtras().getString(KEY_FILEPATH) != null) {
mPath = getFilesDir().getAbsolutePath() + getIntent().getExtras().getString(KEY_FILEPATH);
mFileEditText.setText(loadFile(mPath));
}
mCmdSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mPath != null)
saveFile(mFileEditText.getText().toString(), mPath);
}
});
}
public String loadFile (String _path) {
String _line = "";
String _str_line = "";
BufferedReader inputReader = null;
if (_path == null){
Toast.makeText(this, "Error: No file path provided", Toast.LENGTH_LONG).show();
return "";
}
try {
inputReader = new BufferedReader(new FileReader(_path));
while ((_line = inputReader.readLine()) != null) {
_str_line += _line + "\n";
}
}
catch (Exception e){
Toast.makeText(this, "Error loading \"" + _path + "\"\n\n" + e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}
finally {
try {
if (inputReader != null)
inputReader.close();
}
catch (Exception e){}
}
return _str_line;
}
public boolean saveFile (String _file_text, String _path){
FileOutputStream fos = null;
try{
File f = new File(_path);
fos = new FileOutputStream(f);
fos.write(_file_text.getBytes());
Toast.makeText(this, getString(R.string.saved), Toast.LENGTH_SHORT).show();
return true;
}
catch (Exception e){
Toast.makeText(this, "Error saving \"" + _path + "\"\n\n" + e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}
finally {
try {
if (fos != null)
fos.close();
}
catch (Exception e){
}
}
return false;
}
@Override
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left);
}
}