|
- import java.util.*;
. Z8 w7 w Z* \, e7 ]- E# o - import android.view.*;
: F! V4 Z$ C! H& x4 g% z5 z$ b; z - import android.widget.*;
6 B2 S- S; Y- k# i5 M* W& l9 [ - import java.io.*;
6 L2 }& ?+ w, i# m" f: H. P4 Q - public class Main {
+ P" I7 I+ k2 v3 o, b+ k - public static void main(String[] args) {3 P9 d4 S% y3 j V
- System.out.println("HelloWorld");& p: I9 n8 p: A' T
- }- [' i* C$ J. {2 @0 s' K$ z' g
- public static void fileput(String str){
: ]3 M; X! x H2 j - byte []aa=new byte[1024];$ p: n% G, m& @& y: ?7 h3 x2 ?. P
- //实例化
6 a1 Y! p+ E+ ` K. Y1 K3 u; {" d3 L - FileOutputStream textput = null;0 ^4 s0 R& m$ o8 f. O
- try {
! H7 R F% s) o% K - textput=this.openFileOutput("文件名字.txt", MODE_APPEND);! G% a: I" C3 ]0 a3 X
- try {/ r' P+ T) B: m4 Z
- textput.write(str.getBytes());
$ i2 L# P) f- \! E: |- P- E+ ^ - }catch (IOException e){( ^* d/ C# u- N" I6 v3 |
- }. U4 D! \* S+ _* i
- }catch (FileNotFoundException e){$ C# R& m3 D: I& g
- try{
! \0 k, } T+ m, p7 k - textput.close();//关闭输入流, a& }# n/ I& l" D1 ^1 W
- }. ]5 ?0 i8 V/ B/ X
- catch (IOException ea){ `) G' T" ]6 l
- }
- i+ L& |5 {, g' L - }' |# I" T6 s2 \, o& V
- }
: w1 K; Y% ]) ]/ N1 a! r9 } - public static void fileget() {
' |( t) w( w7 K! f2 N4 \3 j0 s) J W - FileInputStream opedoc = null;; A0 P3 x" \, y6 ~6 ]0 x/ k: [: I
- //实化读取文件输入流,失败返回
T4 f. k3 Z3 h) E& e' S8 j - try9 x" X4 W! e/ H. P U- ?
- {
5 l3 H/ b; E1 q* I' c - opedoc = this.openFileInput("文件名字.txt");
, |2 S1 ~) L# A% l9 a; a - //获得输入流& U# m5 Q4 y' S* Q" B, o
- try+ f+ {# P1 K) n6 L% w/ x
- {- F5 O/ L Z+ n3 Y! L) T
- opedoc.read(aa);5 n2 O1 g0 I; E0 L# g; K
- }
5 I9 x+ L& Q0 m/ U5 _3 g - catch (IOException e)- M1 X- r+ F0 X3 j
- {
$ j6 {$ }8 B1 t' V8 l. S6 x$ ] - }( H$ p* Q% r7 I+ D7 t4 b: J
- }
% \7 y6 X/ U ?. { - catch (FileNotFoundException e)/ X& x& |+ R* i; `# t' I# ?
- {6 A& m6 P" O3 y
- try
+ L' d$ u% ~% ^6 {$ e - {; L! `+ c! q9 g
- opedoc.close();
' S9 V5 v: y" y) U7 Y - }2 @5 ~$ t% W! Z# L* G
- catch (IOException en)( B/ a6 f+ S7 ~) `8 d
- {
: j7 x1 L/ w0 m- N, V! g! x; a u -
; M8 T3 c3 L/ e8 a* [$ l - }
5 _! D C3 }6 V - }
: _; @& q2 O E) p- Q4 ^# w - //强制转换为String型,) J q" Q% w _* v: p/ B
- //因为读出来的是byte型! m! z$ C( ?. |3 u3 h) y1 D5 E
- return new String(aa);
; X# {. n; g9 L$ E+ p - }+ A# b4 c! M0 A3 R) B% A, P9 A' x
- }
) n! X' u3 W1 F0 Z# o4 [
复制代码 |
|