我尝试在我的文件夹中,在内部存储中保存txt文件,但每次都遇到同样的问题:
"未找到来源"
我用不同的方式编写我的代码,如下所示,但在各方面我都有同样的问题.
值得一提的是,我甚至补充道
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
在Manifest.xml中,内部存储不需要.
不用说我在/ data/data/package/files路径中保存文件没有任何问题,但是当我在文件的根目录中添加我的文件夹时,例如/ data/data/package/files/myforlder /myfile.txt我面临"未找到来源"问题.
你能指出我正确的方向来解决这个问题吗?
第二个问题是,用于将文件保存在外部存储器中的外部文件夹中.
(例如:sdCard或USB存储)情况不同或是否相同?
第一种方式:
OutputStreamWriter out;
try {
File path=new File(getFilesDir(),"myfolder");
File mypath=new File(path,"myfile.txt");
if (!mypath.exists()) {
out = new OutputStreamWriter(openFileOutput( mypath.getAbsolutePath() , MODE_PRIVATE));
out.write("test");
out.close();
}
}
Run Code Online (Sandbox Code Playgroud)
第二种方式:
OutputStreamWriter out;
try {
ContextWrapper cw = new ContextWrapper(this);
File path = cw.getDir("myfolder", Context.MODE_PRIVATE);
if (!path.exists()) {
path.createNewFile();
path.mkdir();
}
File mypath=new File(path,"myfile.txt");
if (!mypath.exists()) {
out = new OutputStreamWriter(openFileOutput( mypath.getAbsolutePath() , MODE_PRIVATE));
out.write("test");
out.close();
} …Run Code Online (Sandbox Code Playgroud) 我在C#中有一个结构,我根据我在这里表达的代码定义了我的结构的数组列表.我在我的数组列表中添加项目,但我也需要从列表中删除几行.你能帮我解决一下如何从结构数组列表中删除项目或项目:
public struct SwitchList
{
public int m_Value1, m_Value2;
public int mValue1
{
get { return m_Value1; }
set {m_Value1 = value; }
}
public int mValue2
{
get { return m_Value2; }
set {m_Value2 = value; }
}
}
//Define an array list of struct
SwitchList[] mSwitch = new SwitchList[10];
mSwitch[0].mValue1=1;
mSwitch[0].mValue2=2;
mSwitch[1].mValue1=3;
mSwitch[1].mValue2=4;
mSwitch[2].mValue1=5;
mSwitch[2].mValue2=6;
Run Code Online (Sandbox Code Playgroud)
现在我如何删除我的一个项目,例如项目1.谢谢.