java 中IO流操作字符串 两个文件中有一些相同的代码 现在要将两个合并成一个 并且去除相同代码 祥看补充

文件1functiongetJsonData(url,type){varjsonData='';$.ajax({type:'post',url:url,dataType:... 文件1
function getJsonData(url, type) {
var jsonData = '';
$.ajax({
type: 'post',
url: url,
dataType: 'json',
data: 'type=' + type,
async: false,
success: function(data) {
jsonData = data;
}
});
return jsonData;
}
$(function() {
var data = getJsonData(chart_GetJsonData.action, canvas_bing);
var can = $('#' + 'canvas1').get(0).getContext('2d');
window.myPie = new Chart(can).Pie(data);
});
文件2
$(function() {
var data = getJsonData(chart_GetJsonData.action, canvas_bing);
var can = $('#' + 'canvas2').get(0).getContext('2d');
window.myPie = new Chart(can).Pie(data);
});
展开
 我来答
匿名用户
2015-11-27
展开全部
你 看 看 这 个 ,是不是符合你的要求

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class TestOne {
/**
* @param args
*/
public static void main(String[] args) {
String filepath1 = "F:\\1.txt";
String filepath2 = "F:\\2.txt";
List<String> res1txt = null;
List<String> res2txt = null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//输入连续的个数
System.out.print("Input series string size:");
try {
int temp = Integer.parseInt(br.readLine());
res1txt = readFile(filepath1, temp);
res2txt = readFile(filepath2, temp);
//比较两个list中的相同值
for (int i = 0; i < res1txt.size(); i++) {
for (int j = 0; j < res2txt.size(); j++) {
if(res1txt.get(i).equals(res2txt.get(j))){
System.out.println(res1txt.get(i));
}
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if(br != null)
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 读取文件,把结果以输入的连续个数分割,并保存在List中
* @param filepath
* @param size
* @return
*/
public static List<String> readFile(String filepath, int size){
//如果size不合法,则返回空
if(size <= 0)
return null;
List<String> list = new ArrayList<String>();
BufferedReader br = null;
try {
//读文件
br = new BufferedReader(new InputStreamReader(new FileInputStream(filepath)));
String temp = null;
while((temp = br.readLine()) != null){
for (int i = 0; i < temp.length() - size; i++) {
list.add(temp.substring(i, i+size));
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if(br != null)
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return list;
}
}
这里发不了代码,只能以文本的形式了
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class TestOne {

/**
* @param args
*/
public static void main(String[] args) {
String filepath1 = "F:\\1.txt";
String filepath2 = "F:\\2.txt";
List<String> res1txt = null;
List<String> res2txt = null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//输入连续的个数
System.out.print("Input series string size:");

try {
int temp = Integer.parseInt(br.readLine());
res1txt = readFile(filepath1, temp);
res2txt = readFile(filepath2, temp);
//比较两个list中的相同值
for (int i = 0; i < res1txt.size(); i++) {
for (int j = 0; j < res2txt.size(); j++) {
if(res1txt.get(i).equals(res2txt.get(j))){
System.out.println(res1txt.get(i));
}
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if(br != null)
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

/**
* 读取文件,把结果以输入的连续个数分割,并保存在List中
* @param filepath
* @param size
* @return
*/
public static List<String> readFile(String filepath, int size){
//如果size不合法,则返回空
if(size <= 0)
return null;
List<String> list = new ArrayList<String>();
BufferedReader br = null;
try {
//读文件
br = new BufferedReader(new InputStreamReader(new FileInputStream(filepath)));
String temp = null;
while((temp = br.readLine()) != null){
for (int i = 0; i < temp.length() - size; i++) {
list.add(temp.substring(i, i+size));
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if(br != null)
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return list;
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式