-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
...va/edu/hzuapps/androidworks/homeworks/Net1314080903212/Net1314080903212GetRemoteFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.example.dell.multichat; | ||
|
||
import android.os.Environment; | ||
import android.os.Handler; | ||
import android.os.Looper; | ||
import android.os.Message; | ||
import android.renderscript.ScriptGroup; | ||
import android.widget.TextView; | ||
|
||
import java.io.BufferedInputStream; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.RandomAccessFile; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.net.URLConnection; | ||
|
||
/** | ||
* Created by dell on 2016/4/28. | ||
*/ | ||
public class Net1314080903212GetRemoteFile implements Runnable{ | ||
public TextView GRFshow; | ||
public Handler sendHandler; | ||
|
||
public void Net1314080903212GetRemoteFile(Handler handler) | ||
{ | ||
sendHandler = handler; | ||
} | ||
|
||
public void run() | ||
{ | ||
try { | ||
System.out.println("before new URL!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); | ||
URL git_url = new URL("https://raw.githubusercontent.com/OurScream/PerIntBank/master/README.md"); | ||
|
||
System.out.println("before new URLConnection!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); | ||
//打开url链接 | ||
URLConnection git_con = git_url.openConnection(); | ||
|
||
//获取数据 | ||
// InputStream is = git_con.getInputStream(); //方法1 | ||
// BufferedInputStream bis = new BufferedInputStream(is); | ||
InputStream bis = git_url.openStream(); //方法2 | ||
|
||
int read_len = 0; | ||
byte[] readbyte = new byte[1024]; | ||
|
||
System.out.println("before new get_path!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); | ||
//新建文件 | ||
File get_path = Environment.getExternalStorageDirectory(); // | ||
File file = new File(get_path.getCanonicalPath() , "ChatHistory"); | ||
|
||
//判断历史记录文件是否存在, 不存在则创建 | ||
if (!file.exists()){ | ||
file.createNewFile(); | ||
System.out.println("GetRemoteFile: 创建文件!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); | ||
} | ||
|
||
while((read_len = bis.read(readbyte)) != -1) | ||
{ | ||
RandomAccessFile raf = new RandomAccessFile(file,"rw"); | ||
raf.seek(file.length()); | ||
raf.write(readbyte); //这里的换行不知道可不可以! | ||
System.out.println(readbyte.toString() + "GetRemoteFile: 看看一条记录大概都长:" + file.length()); | ||
raf.close(); | ||
} | ||
//再读一次文件 | ||
Message msg = new Message(); | ||
msg.what = 0x789; | ||
sendHandler.sendMessage(msg); | ||
|
||
// new Net1314080903212RH().file_read(new Net1314080903212MultiChat().show); | ||
} | ||
catch(MalformedURLException murle) | ||
{ | ||
murle.printStackTrace(); | ||
} | ||
catch(IOException ioe) | ||
{ | ||
ioe.printStackTrace(); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...in/java/edu/hzuapps/androidworks/homeworks/Net1314080903212/Net1314080903212MultiChat.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
实验7:网络编程 |