代码片段(假设只有3个key=value):

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(
new InputStreamReader(
new FileInputStream("C:\\Users\\Administrator\\Desktop\\test.txt"),"GBK"));
String str = "";
Map<String,String> map = new LinkedHashMap<String,String>();
String value = null,key = null;
int i = 0;
while((str=br.readLine())!=null) {
System.out.println(str);
if(str.contains("=")) {
i++;
if(null != value && null != key) {
map.put(key,value);
}
key = str.substring(0,str.indexOf("="));
value = str.substring(str.indexOf("=")+1,str.length());
if(i == 3) {
map.put(key,value);
} else {
continue;
}
}
value += str;
}
System.out.println(map);
}

输出结果:

a.b=c
yes=jsh健康四年的空间能看见能看到今年的空间能健康的上vdk
空间的时刻
空间的四年看电视vjnk
扣篮大赛女款东京
nj=klm
{a.b=c, yes=jsh健康四年的空间能看见能看到今年的空间能健康的上vdk空间的时刻空间的四年看电视vjnk扣篮大赛女款东京, nj=klm}

PS:如果修改某个key-value值,一定要遍历重写txt文件吗。。。

读取以key=value形式存储的txt文件的更多相关文章

  1. Android 读取手机SD卡根目录下某个txt文件的文件内容

    1.先看activity_main.xml文件: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/and ...

  2. php 读取网页源码 , 导出成txt文件, 读取xls,读取文件夹下的所有文件的文件名

    <?php // 读取网页源码$curl = curl_init();curl_setopt($curl, CURLOPT_URL, $url);curl_setopt($curl, CURLO ...

  3. Opencv读取图片像素值并保存为txt文件

    #include <opencv2/opencv.hpp>#include<vector>#include <fstream> using namespace st ...

  4. python web开发-flask读取txt文件内容

    某些情况下,需要读取flask网站要目录下的txt文件.但是直接在flask网站的目录下创建一个文件是无法访问的.从网站找了一些资料,最终发现通过写一个方法返回txt内容比较简单方便,不过此方法适用于 ...

  5. 将txt文件数据存入excel表格

    前言 最近使用Appium自动化在测试设备配网的情况,需要记录每次成功与否和耗时时间. 由于App不是很稳定,执行一段时间会奔溃,因此数据只能通过追加的形式写入到txt文件. 实现过程 存储在txt文 ...

  6. 图片转换成十六进制TXT文件

    最近学习了图片的转换,就学习了一下图片从二进制转换成十六进制,十六进制TXT文件转换成图片形式. using System; using System.Collections.Generic; usi ...

  7. (完整)爬取数据存储之TXT、JSON、CSV存储

    一.文件存储 1. TXT文本存储 例:知乎发现页面,获得数据存成TXT文本 import requests from pyquery import PyQuery as pq url="h ...

  8. Python3爬虫(八) 数据存储之TXT、JSON、CSV

    Infi-chu: http://www.cnblogs.com/Infi-chu/ TXT文本存储 TXT文本存储,方便,简单,几乎适用于任何平台.但是不利于检索. 1.举例: 使用requests ...

  9. 按行读取TXT文件中的内容

    public Dictionary<int, string> GetDicFromLog() { try { StreamReader sr = new StreamReader(file ...

随机推荐

  1. codevs:2849 素数判定 3:输入一个正整数x(3<=x<=100000),判断x是否是质数,如果是质数则输出信息“prime”,否则输出“composite”。

    #include<iostream>#include<cstdio>#include<cmath>using namespace std;int a[2];int ...

  2. POJ 1927 Area in Triangle

    Area in Triangle Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 1674   Accepted: 821 D ...

  3. Java ArrayList对象集合去重

    import java.util.ArrayList; import java.util.Iterator; public class StringSampleDemo { public static ...

  4. Parse发布Bolts,一个面向iOS和Android的底层库集合

    转载自:http://www.infoq.com/cn/news/2014/02/parse-announces-bolts 数月前,Parse被Facebook收购.最近,它开源了一个面向iOS和A ...

  5. Bmob-Rest-API之使用

    针对最近这样的需求,某个功能插入数据成功并实时同步到Bmob云上的数据库. 本来想在Bmob上找一个用Java写的,找了一圈发现没有,于是便采用Bmob的Rest-API方式进行数据插入. 另外补充一 ...

  6. graph embedding 使用方法

    无论是network embedding 还是graph embedding都是通过节点(node)和边的图,学出每个节点的embedding向量. 比较流行的算法有: Model Paper Not ...

  7. python 处理geoJson to shp 互转

  8. 网络分裂 redis 集群

    REDIS cluster-tutorial -- Redis中文资料站 -- Redis中国用户组(CRUG) http://www.redis.cn/topics/cluster-tutorial ...

  9. 007 CSS基本选择器

    复习. 一:类选择器 1.多类名选择器 使用场景:某个标签上需要多个类进行描述. 多个类之间使用空格分开. 冲突的时候,和类名在html中的先后顺序没有关系,和css中的样式的先后顺序有关系. 2.案 ...

  10. XSS平台-学习

    单点登录 - Telnet 404https://sso.telnet404.com/cas/login?service=https%3A%2F%2Fwww.seebug.org%2Faccounts ...