Inner File Storage

一,说明

  • 保存应用运行时需要较大的数据或图片
  • 文件类型:任意
  • 存储路径:/data/data/packageName/files/
  • 可以设置为当前应用私有
  • 应用卸载时删除此数据

二,API

读取文件
  • FileInputStream fis=openFileInput("logo.png")
    得到文件输入流
保存文件
  • FileOuputStream fos=openFileOutput("logo.png",MODE_PRIVATE)
    得到文件输出流
files文件夹
  • File filesDir=getFilesDir()
    得到文件夹
操作assets下文件
  • AssetManager context.getAssets()
    得到AssetManager
  • InputStream AssetManager.open(String fileName)
    得到asset下文件输入流
加载图片文件
  • Bitmap BitmapFactory.decodeFile(String pathName)
    得到BItmap(.bmp/.png/.jpg)

三,测试源码

public class IFActivity extends Activity {
    private ImageView iv_if_image;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_if);
        iv_if_image = (ImageView) findViewById(R.id.iv_if_image);
    }

    public void onClickSave(View V) throws IOException {
        //1. 得到输入流
        AssetManager assetManager = getAssets();
        InputStream is = assetManager.open("logo.png");
        //2. 得到输出流
        FileOutputStream fos = openFileOutput("logo.png", MODE_PRIVATE);
        //3. 边读边写
        byte[] buffer=new byte[128];
        int len=-1;
        while((len=is.read(buffer))!=-1){
            fos.write(buffer,0,len);
        }
        fos.close();
        is.close();
        //4. 提示
        Toast.makeText(this, "保存完成", 0).show();
    }

    public void onClickRead(View V) {
        //1. 加载图片得到Bitmap
        String filesPath = getFilesDir().getAbsolutePath();
        String imagePath=filesPath+"/logo.png";
        Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
        //2. 显示图片
        iv_if_image.setImageBitmap(bitmap);
    }
}
File "/data/coding/transformers_from_scratch-main/pretrain.py", line 144, in <module> main() File "/data/coding/transformers_from_scratch-main/pretrain.py", line 125, in main trainer.train() File "/data/miniconda/envs/torch/lib/python3.10/site-packages/transformers/trainer.py", line 2240, in train return inner_training_loop( File "/data/miniconda/envs/torch/lib/python3.10/site-packages/transformers/trainer.py", line 2622, in _inner_training_loop self._maybe_log_save_evaluate( File "/data/miniconda/envs/torch/lib/python3.10/site-packages/transformers/trainer.py", line 3102, in _maybe_log_save_evaluate self._save_checkpoint(model, trial) File "/data/miniconda/envs/torch/lib/python3.10/site-packages/transformers/trainer.py", line 3199, in _save_checkpoint self.save_model(output_dir, _internal_call=True) File "/data/miniconda/envs/torch/lib/python3.10/site-packages/transformers/trainer.py", line 3898, in save_model self._save(output_dir, state_dict=state_dict) File "/data/miniconda/envs/torch/lib/python3.10/site-packages/transformers/trainer.py", line 4015, in _save self.model.save_pretrained( File "/data/miniconda/envs/torch/lib/python3.10/site-packages/transformers/modeling_utils.py", line 3572, in save_pretrained ptrs[id_tensor_storage(tensor)].append(name) File "/data/miniconda/envs/torch/lib/python3.10/site-packages/transformers/pytorch_utils.py", line 300, in id_tensor_storage from torch.distributed.tensor import DTensor cannot import name 'DTensor' from 'torch.distributed.tensor' (/data/miniconda/envs/torch/lib/python3.10/site-packages/torch/distributed/tensor/__init__.py)
07-01
C:\Users\lenovo\anaconda3\envs\radi\python.exe F:\PythonProject2\transform.py Traceback (most recent call last): File "F:\PythonProject2\transform.py", line 29, in <module> output_file = convert_xls_to_xlsx(input_file) File "F:\PythonProject2\transform.py", line 18, in convert_xls_to_xlsx df = pd.read_excel(input_path, engine='xlrd') File "C:\Users\lenovo\anaconda3\envs\radi\lib\site-packages\pandas\util\_decorators.py", line 311, in wrapper return func(*args, **kwargs) File "C:\Users\lenovo\anaconda3\envs\radi\lib\site-packages\pandas\io\excel\_base.py", line 364, in read_excel io = ExcelFile(io, storage_options=storage_options, engine=engine) File "C:\Users\lenovo\anaconda3\envs\radi\lib\site-packages\pandas\io\excel\_base.py", line 1233, in __init__ self._reader = self._engines[engine](self._io, storage_options=storage_options) File "C:\Users\lenovo\anaconda3\envs\radi\lib\site-packages\pandas\io\excel\_xlrd.py", line 25, in __init__ super().__init__(filepath_or_buffer, storage_options=storage_options) File "C:\Users\lenovo\anaconda3\envs\radi\lib\site-packages\pandas\io\excel\_base.py", line 420, in __init__ self.book = self.load_workbook(self.handles.handle) File "C:\Users\lenovo\anaconda3\envs\radi\lib\site-packages\pandas\io\excel\_xlrd.py", line 38, in load_workbook return open_workbook(file_contents=data) File "C:\Users\lenovo\anaconda3\envs\radi\lib\site-packages\xlrd\__init__.py", line 148, in open_workbook bk = book.open_workbook_xls( File "C:\Users\lenovo\anaconda3\envs\radi\lib\site-packages\xlrd\book.py", line 92, in open_workbook_xls biff_version = bk.getbof(XL_WORKBOOK_GLOBALS) File "C:\Users\lenovo\anaconda3\envs\radi\lib\site-packages\xlrd\book.py", line 1278, in getbof bof_error('Expected BOF record; found %r' % self.mem[savpos:savpos+8]) File "C:\Users\lenovo\anaconda3\envs\radi\lib\site-packages\xlrd\book.py", line 1272, in bof_error raise XLRDError('Unsupported format, or corrupt file: ' + msg) xlrd.biffh.XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b'diagnost'
07-17
### Inner Cache and Peer Cache Concepts In the context of computer systems or networks, both **inner cache** and **peer cache** serve as mechanisms to improve data access speed by storing frequently accessed information closer to where it is needed. However, their roles and implementations differ significantly. #### Definition of Inner Cache An **inner cache**, often referred to as an internal cache, resides within a single system component such as a CPU core or memory controller. It stores copies of recently used data from main memory or other storage devices to reduce latency when accessing this data again. This type of caching improves performance at the local level without requiring communication with external components[^1]. For example, Level 1 (L1), Level 2 (L2), and sometimes even Level 3 (L3) caches found inside modern processors are examples of inner caches designed specifically for high-speed operations directly tied into individual processing units. #### Definition of Peer Cache On the contrary, **peer cache** refers more broadly across distributed environments like networked computers sharing resources through interconnections rather than being confined solely within one device's architecture alone; here multiple nodes act collaboratively forming what could be termed 'peers'. When any node requests certain pieces of content not already present locally but available elsewhere among these interconnected peers then instead retrieving anew each time they can opt querying others first who might have cached versions thereby saving bandwidth while speeding up delivery times overall compared against traditional methods involving direct server calls every instance required fresh downloads etcetera.[^2] #### Key Differences Between Them | Aspect | Inner Cache | Peer Cache | |---------------------|--------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------| | Location | Within specific hardware components | Across different machines/nodes | | Communication Scope | Limited mainly internally | Requires interaction between various entities | | Purpose | To enhance localized operation efficiency | Facilitates resource-sharing amongst several participants | | Example Usage | Processor L1/L2 Caching | Content Delivery Networks(CDNs); Distributed File Systems | While learning about Spring Boot integration with technologies including Redis may focus primarily on application development aspects related database management solutions offered via software frameworks [^3], understanding fundamental principles behind how underlying architectures manage memory hierarchies remains crucial especially considering potential optimizations achievable depending upon use cases encountered during real-world projects execution phases accordingly thus enhancing technical expertise further beyond mere coding skills acquisition only! ```python # A simple Python code snippet demonstrating basic usage of Redis client in conjunction with Flask framework underpinning concepts discussed earlier regarding efficient handling stored values efficiently leveraging appropriate layers throughout entire stack design process. from flask import Flask import redis app = Flask(__name__) cache = redis.Redis(host='localhost', port=6379) @app.route('/') def hello(): count = cache.incr('hits') return f'Hello World! I have been seen {count} times.' if __name__ == "__main__": app.run(debug=True) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值