diff --git a/soft1614080902411/AndroidManifest.xml b/soft1614080902411/AndroidManifest.xml new file mode 100644 index 000000000..c7cf7a2ee --- /dev/null +++ b/soft1614080902411/AndroidManifest.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/soft1614080902411/Java/Main2Activity.java b/soft1614080902411/Java/Main2Activity.java new file mode 100644 index 000000000..723364b74 --- /dev/null +++ b/soft1614080902411/Java/Main2Activity.java @@ -0,0 +1,193 @@ +package com.example.edu.hzu.myapplication4; + +import android.content.Intent; +import android.os.Bundle; +import android.support.design.widget.FloatingActionButton; +import android.support.design.widget.Snackbar; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.View; +import android.widget.Button; +import android.content.Context; +import android.os.Bundle; +import android.os.Environment; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import com.example.edu.hzu.myapplication4.R; + +public class Main2Activity extends AppCompatActivity { + public static final String DIRECTORY = "demo"; + public static final String FILENAME = "file_demo.txt"; + public static final String TAG = Main2Activity.class.getSimpleName(); + + @Override + + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main2); + ((Button) findViewById(R.id.bt2)).setOnClickListener(new View.OnClickListener() { + + @Override + + public void onClick(View view) { + String text = ((EditText) findViewById(R.id.edit1)).getText().toString(); + saveTextIntoInternalStorage(text); + } + + }); + ((Button) findViewById(R.id.bt4)).setOnClickListener(new View.OnClickListener() { + + @Override + + public void onClick(View view) { + Intent intent=new Intent(Main2Activity.this,Main3Activity.class); + startActivity(intent); + } + }); + } + // 将文字保存到内部存储 + private void saveTextIntoInternalStorage(String text) { + // 获取内部存储目录 + File dir = this.getFilesDir(); + //File dir = getCacheDir(); + if (dir.isDirectory()) { +// dir.mkdir(); +// dir.mkdirs(); + } + if (dir.isFile()) { + // D:/Abc.txt , -> D:/Abc1.txt ->D:/abc.txt + } + File file = new File(dir, FILENAME); +// try { +// File = File.createTempFile(FILENAME, null, dir); +// } catch (IOException e) { +// e.printStackTrace(); +// } + if (file.exists()) { // 判断文件是否存在 + Log.i(TAG, file.getAbsolutePath()); + Log.i(TAG, file.length() + ""); // bytes*1024=kb *1024 MB + Log.i(TAG, file.isFile() + ""); + file.canRead(); + file.canWrite(); + file.canExecute(); + file.getFreeSpace(); + file.getTotalSpace(); + } + FileOutputStream fos = null; // 字节流 | char | cn : gbk 2 bytes, utf8 3 bytes + try { // 使用API打开输出流 + fos = openFileOutput(FILENAME, MODE_PRIVATE); + //FileOutputStream fos = new FileOutputStream(file); + fos.write(text.getBytes()); // 写入内容 + fos.close(); // 关闭流 + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + fos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + FileReader reader = null; // char + try { + reader = new FileReader(file.getAbsoluteFile()); + BufferedReader bReader = new BufferedReader(reader); + String line = bReader.readLine(); + Log.i(TAG, "从文件读取的内容: " + line); + bReader.close(); + reader.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + // 显示结果 + showResult(file.getAbsolutePath()); + // 删除文件 + // file.delete(); + // deleteFile(FILENAME); + } + // 将文字保存到外部存储 + private void saveTextIntoExternalStorage(String text) { + if (!isExternalStorageWritable()) { + Log.e(TAG, "外部存储不可写!"); + return; + } + File dir = getPublicExtStorageDir(DIRECTORY, Environment.DIRECTORY_DOWNLOADS); + File file = new File(dir, FILENAME); + try { + FileOutputStream fos = new FileOutputStream(file); + fos.write(text.getBytes()); + fos.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + // 显示结果 + showResult(file.getAbsolutePath()); + } + /* Checks if external storage is available for read and write */ + private boolean isExternalStorageWritable() { + String state = Environment.getExternalStorageState(); + if (Environment.MEDIA_MOUNTED.equals(state)) { + return true; + } + return false; + } + /* Checks if external storage is available to at least read */ + private boolean isExternalStorageReadable() { + String state = Environment.getExternalStorageState(); + if (Environment.MEDIA_MOUNTED.equals(state) || + Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { + return true; + } + return false; + } + // 创建公开的外部存储目录(App卸载时不会删除) + private File getPublicExtStorageDir(String dirName, String type) { + if (type == null) { // 指定文件类型 + type = Environment.DIRECTORY_PICTURES; + } + File dir = new File(Environment // + .getExternalStoragePublicDirectory(type), dirName); + if (!dir.mkdirs()) { + Log.e(TAG, "目录无法创建!"); + } + long freeSpace = dir.getFreeSpace(); + Log.i(TAG, "剩余空间大小: " + (freeSpace / 1024 / 1024) + "MB"); + long totalSpace = dir.getTotalSpace(); + Log.i(TAG, "总空间大小: " + (totalSpace / 1024 / 1024) + "MB"); + return dir; + } + // 创建私有的外部存储目录(App卸载时会一同删除) + private File getPrivateExtStorageDir(Context context, String dirName, String type) { + if (type == null) { // 指定文件类型 + type = Environment.DIRECTORY_PICTURES; + } + File file = new File(context // + .getExternalFilesDir(type), dirName); + if (!file.mkdirs()) { + Log.e(TAG, "目录无法创建!"); + } + return file; + } + private void showResult(String result) { + ((TextView) findViewById(R.id.view1)) // + .setText(result.toCharArray(), 0, result.length()); + } +} diff --git a/soft1614080902411/Java/Main3Activity.java b/soft1614080902411/Java/Main3Activity.java new file mode 100644 index 000000000..06acecefe --- /dev/null +++ b/soft1614080902411/Java/Main3Activity.java @@ -0,0 +1,18 @@ +package com.example.edu.hzu.myapplication4; + +import android.os.Bundle; +import android.support.design.widget.FloatingActionButton; +import android.support.design.widget.Snackbar; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.View; + +public class Main3Activity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main3); + } + +} diff --git a/soft1614080902411/Java/MainActivity.java b/soft1614080902411/Java/MainActivity.java new file mode 100644 index 000000000..94b604c07 --- /dev/null +++ b/soft1614080902411/Java/MainActivity.java @@ -0,0 +1,25 @@ +package com.example.edu.hzu.myapplication4; + +import android.content.Intent; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + Button bt1=(Button)findViewById(R.id.bt1); + bt1.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent=new Intent(MainActivity.this,Main2Activity.class); + startActivity(intent); + + } + }); + } +} diff --git a/soft1614080902411/Main2Activity.PNG b/soft1614080902411/Main2Activity.PNG new file mode 100644 index 000000000..5190e620f Binary files /dev/null and b/soft1614080902411/Main2Activity.PNG differ diff --git a/soft1614080902411/Main3Activity.PNG b/soft1614080902411/Main3Activity.PNG new file mode 100644 index 000000000..1ca313b45 Binary files /dev/null and b/soft1614080902411/Main3Activity.PNG differ diff --git a/soft1614080902411/MainActivity.PNG b/soft1614080902411/MainActivity.PNG new file mode 100644 index 000000000..434621335 Binary files /dev/null and b/soft1614080902411/MainActivity.PNG differ diff --git a/soft1614080902411/drawable/ic_launcher_background.xml b/soft1614080902411/drawable/ic_launcher_background.xml new file mode 100644 index 000000000..d5fccc538 --- /dev/null +++ b/soft1614080902411/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/soft1614080902411/drawable/wechat.jpg b/soft1614080902411/drawable/wechat.jpg new file mode 100644 index 000000000..82aab9e9c Binary files /dev/null and b/soft1614080902411/drawable/wechat.jpg differ diff --git a/soft1614080902411/drawable/xiaozhupeiqi.jpg b/soft1614080902411/drawable/xiaozhupeiqi.jpg new file mode 100644 index 000000000..f0becd308 Binary files /dev/null and b/soft1614080902411/drawable/xiaozhupeiqi.jpg differ diff --git a/soft1614080902411/layout/activity_main.xml b/soft1614080902411/layout/activity_main.xml new file mode 100644 index 000000000..916f9737b --- /dev/null +++ b/soft1614080902411/layout/activity_main.xml @@ -0,0 +1,25 @@ + + + + +