Categories: ANDROID APP

Android קריאת וכתיבת קבצים אנדרואיד



Android קריאת וכתיבת קבצים אנדרואיד

bundle il.co.newclass.information;

import android.content material.Context;
import android.os.Bundle;
import android.assist.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class MainActivity extends AppCompatActivity {

String fileName = “aaa.txt”;
@Override
protected void onCreate(Bundle savedInstanceState) {
tremendous.onCreate(savedInstanceState);
setContentView(R.structure.activity_main);
ultimate Context con = this;

((Button) findViewById(R.id.btnread)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

File file = new File(con.getFilesDir(), fileName);

attempt {
if (!file.exists()) {
Toast.makeText(con,”File will not be exists”,Toast.LENGTH_LONG).present();
}
else
{
FileInputStream is = new FileInputStream(file);

InputStreamReader isr = new InputStreamReader(is);

BufferedReader br = new BufferedReader(isr);

String str = br.readLine();
whereas(str!=null)
{

str = br.readLine();
}

br.shut();
isr.shut();
is.shut();

}

}
catch (IOException e)
{
//
}

}
});

((Button) findViewById(R.id.btnwrite)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

File file = new File(con.getFilesDir(), fileName);

attempt {
if (!file.exists()) {
file.createNewFile();
}

FileOutputStream os = new FileOutputStream(file);
byte[] arr = new byte[100];
String str = “abcd!!!!”;

OutputStreamWriter osw = new OutputStreamWriter(os);

osw.write(str);
osw.append(“1111111”);
osw.append(“2222222”);

osw.append(“n”);
osw.append(“1111111”);
osw.append(“2222222”);
osw.append(“n”);
osw.append(“1111111”);
osw.append(“2222222”);
osw.append(“n”);
osw.append(“1111111”);
osw.append(“2222222”);
osw.append(“n”);
osw.append(“1111111”);
osw.append(“2222222”);

osw.shut();
os.shut();

}
catch (IOException e)
{
//
}

}
});
}
}

חיים גלבוע, הדרכה, יעוץ ופתוח תוכנה
haim@newclass.co.il
Haim Gilboa

source

linda

Recent Posts

Tips for Maximizing Your QQDewa Experience

Understanding QQDewa Basics First things first, what's QQDewa all about? Simply put, QQDewa is an…

16 hours ago

Comcast Business: Unlocking Business Growth with Comcast Business

Introduction In today’s digital-first globe, reliable internet is the spine of any successful company. Comcast…

3 days ago

Unlocking Savings and Selection at Costco Business Center

Introduction: Costco Business Center is a specific branch of Costco Wholesale which focuses on serving…

5 days ago

Exploring the Features of Plinkobet Betting

Hey there! If you've stumbled upon this article, you're probably curious about Plinkobet and what…

5 days ago

Ultimate Guide to Online Poker Apps

Hey there, poker enthusiasts! Whether you're a seasoned pro or just starting to shuffle the…

6 days ago

Unlocking Trust: The Role of the Better Business Bureau in Modern Commerce

What Is the Better Business Bureau (BBB)? The Better Business Bureau (BBB) is a non-public,…

6 days ago