1. 程式人生 > >linux主機讀取.txt檔案內容

linux主機讀取.txt檔案內容

//filePath = /home/file/webservice/kis/pubw.txt
public static void readTxt(String filePath){
        try {
                String encoding="GBK";
                File file=new File(filePath);
                if(file.isFile() && file.exists()){ //判斷檔案是否存在
                    InputStreamReader read = new InputStreamReader(
                    new FileInputStream(file),encoding);//考慮到編碼格式
                    BufferedReader bufferedReader = new BufferedReader(read);
                    String lineTxt = null;
                    while((lineTxt = bufferedReader.readLine()) != null){
                        //System.out.println(lineTxt);
                    String mrDetail[] =  lineTxt.split("\\|");
                    //String hour = mrDetail[0].substring(8, 10);
                    String minute = mrDetail[0].substring(10, 12);
                   
                    }
                    read.close();
                   
                    //JSONArray array = JSONArray.fromObject(mrList);
                    //System.out.println("json-->"+array.toString());
                    //writeTxtFile(array.toString());
              
        }else{
            System.out.println("找不到指定的檔案");
        }
        } catch (Exception e) {
            System.out.println("讀取檔案內容出錯");
            e.printStackTrace();
        }
    
    }

相關推薦

linux主機讀取.txt檔案內容

//filePath = /home/file/webservice/kis/pubw.txt public static void readTxt(String filePath){ try { String encodin

java讀取txt檔案內容並計算CPU耗時---以讀完《紅樓夢》為例

01. 學習目的 (1)java讀取TXT文件內容到字串陣列 (2)計算文件讀取過程CPU耗時 02. 實現程式碼 hlm.txt內容: 程式碼 /* #程式開始,獲取系統當前時間 #用檔案輸入流FileInputStream讀取文件內容 #將讀

Java 讀取 txt 檔案內容到容器 List

方法一: 一、桌面上準備 DataObject.txt 檔案,內容為:         二、開啟 Eclipse,編寫程式碼如下:   import java.io.BufferedRe

winfrom 從本地讀取txt檔案內容新增到窗體上

我使用的是dev 中的memoEdit控制元件(和textbox類似) 下面看程式碼 private void GetFileText() { //獲取檔案相對路徑 string path = System.Windows

C++用fscanf()函式讀取TXT檔案內容

fscanf()函式的標頭檔案是<stdio.h>,函式原型為int fscanf(FILE*stream, constchar*format, [argument...]); 其功能為根據資料格式(format)從輸入流(stream)中寫入資料(argume

MFC逐行讀取txt檔案內容

程式碼如下: CString strFileName = _T("D:\\abc.txt"); if (!PathFileExists(strFileName)) { return FALS

讀取TXT檔案內容,生成Excel檔案

 需要用到jar檔案:poi-3.0.1.jarpackage office; /** * 解析txt檔案,輸出到Excel檔案 * @author JavaAlpha * @date 2011-7-28 * @version V 1.0 */ import j

c#如何讀取txt檔案內容

using System; using System.Collections; using System.Configuration; using System.Data; using System

C格式化讀取txt檔案內容

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> struct localtion{ unsigned int lx; unsigned int ly

java讀取txt檔案並解析其內容

package readtext;/* @author wb @great forever i think,therefor i am */ import java.io.BufferedReader; import java.io.FileInputStream; import java

讀取網路TXT檔案內容解決中文亂碼

 private String getServerVersion(final String urlStr) {      new Thread(){         

python中讀取txt檔案,windows下麼有毛病,到Linux下總是隻有最後一行有效,怎麼解決?

比如:這個txt有5行, fin = open('F:\\temp\\name.txt','r') for line in fin: strsname = line.rstrip('\n') AAA('F:\\temp','F:\\temp\\2',str

php 讀取txt檔案中的內容,轉換成陣列

$str = file_get_contents('weixinname.txt');//將整個檔案內容讀入到一個字串中 $str_encoding = mb_convert_encod

python 讀取txt檔案,將內容寫入excel表格

# -*- coding: UTF-8 -*- import os import time import openpyxl as openpyxl Parser_version = 'version_1.0' print Parser_version items = os.listdir(".")

檔案 —— WEB前端讀取本地檔案內容哪些事(前臺解析txt檔案)……

強制讓瀏覽器允許JS讀寫本地檔案……的操作!問題描述:讓自己的瀏覽器允許js讀寫本地檔案,儘可能多的相容各種瀏覽器。(即本機的js檔案讀寫本機的檔案)問題回覆——1:您的意思是不需要瀏覽器與使用者互動直接操作使用者機上的檔案?不符合瀏覽器的安全標準,屬於瀏覽器的設計缺陷所以瀏

MapReduce讀取txt檔案儲存至HBase,以檔名作Key,整個檔案內容作Value

把已抓取好的網路輿情資訊(以txt形式存放),儲存到HBase中,再進行資訊分析。 要求: 以檔名作Key,整個檔案內容作Value 思路: txt檔案先上傳到HDFS中,再使用HBase MapReduce將檔案寫入HBase中。(很簡單的思路) 問題分析:

Adobe指令碼之如何讀取txt檔案的文字內容

在Adobe指令碼編寫中,讀取檔案內容分為以下三個步驟: 開啟檔案對話方塊,獲取該檔案 設定該檔案為“可讀”模式 讀取檔案內容 程式碼如下: 1. 建立測試介面 首先我們先構建一個U

python讀取 .txt 文字內容以及將程式執行結果寫入txt檔案

** 1、讀入篇 ** python對處理文字這方面還是很有優勢的,像普通1G左右的文字都可以直接讀到記憶體中去處理,進行文字處理的速度是非常的快。 話不多說,上程式碼,講思路。 #c

Pdfminer讀取PDF檔案內容儲存到本地TXT

from pdfminer.converter import PDFPageAggregator from pdfminer.layout import LTTextBoxHorizontal, LAParams from pdfminer.pdfinterp

C#讀取txt檔案並畫圖

tools.cs using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; us