導航:首頁 > 編程語言 > javadat解析

javadat解析

發布時間:2022-05-08 15:59:00

① 如何用java程序查看.dat文件

如果你的dat文件被加密過,那麼需要解密才能看,否則讀出來的都是亂碼,如果沒有加密,那麼通過io流,反正java的io流可以把裡面的所有字元都讀出來,方法就多了去了,到網路中查找java讀文件就可以找出一堆代碼

② java怎樣獲取指定目錄下的所有「.dat」文件,並且解析獲取這些文件中的數據

獲取文件名很簡單
但獲取數據要看其內容格式,一般需要預先知道其格式才能讀取

③ java如何讀取D盤下面的所有*.dat文件!

1、獲取d:\ 目錄下所有的文件,需要考慮是否需要遞歸。這里主要用到File等類
2、對每個文件名解析,判斷是否是dat文件
3、對每個dat文件讀取,主要用到InputStreamReader等類
4、生成目錄,主要用到File類里的API

④ 請問java程序生成的dat數據文件用什麼軟體工具可以打開查看

.dat並不是一種格式,任何格式的數據都可以存儲為.dat格式
你用文本編輯器打開看看是不是普通的文本數據格式,還是其他編碼格式的,用相應的方法就可以了
沒有一個100%能打開所有DAT文件的軟體,如果記事本打不開那怎麼辦呢?套用那句老話「解鈴還須系鈴人」,因此您得知道這個「系鈴人」是誰(就是對應的程序是哪個)!下面有一些辦法:
有時候我們在接受郵件附件時也會偶爾收到DAT格式文件,那麼我們先嘗試下記事本能否打開,如果不能就要詢問發郵件的人:這是一個什麼文件?如果回答是圖片,您就可以嘗試修改擴展名後用圖片查看器打開,如果說是個視頻,此時你可以嘗試使用暴風影音。
對於一些奇怪的現象:一些郵件程序會自動將附件的原有格式改成DAT格式。比如一張名為mtoou.jpg的圖片,它會自動改成mtoou.dat。如果你知道,那麼再將dat改成jpg就可以了。如果不知道您還是需要詢問發件者到底是這個DAT文件是個什麼格式的。
不知不覺也打了這么多,位的就是要說明:DAT文件是個未知數,裡面存放著什麼只有創建它的程序才知道。如果您不知道它是否是別的文件格式改成了DAT格式,那可以先嘗試用記事本打開,如果不行那麼就要詢問給您這個DAT文件的人了。

你試下如果改成JAVA文件後綴 用編碼utf-8 試試

⑤ JAVA中怎麼讀取DAT文件中的內容

DAT估計是個二進制或者文本跟普通讀取文件是一樣的
讀取上來你再對文件格式進行拆分首先你要了解它的格式是什麼你可以用
NOTEPAD++或者C32ASM打開看看

publicclassReadFromFile{
/**
*以位元組為單位讀取文件,常用於讀二進制文件,如圖片、聲音、影像等文件。
*/
(StringfileName){
Filefile=newFile(fileName);
InputStreamin=null;
try{
System.out.println("以位元組為單位讀取文件內容,一次讀一個位元組:");
//一次讀一個位元組
in=newFileInputStream(file);
inttempbyte;
while((tempbyte=in.read())!=-1){
System.out.write(tempbyte);
}
in.close();
}catch(IOExceptione){
e.printStackTrace();
return;
}
try{
System.out.println("以位元組為單位讀取文件內容,一次讀多個位元組:");
//一次讀多個位元組
byte[]tempbytes=newbyte[100];
intbyteread=0;
in=newFileInputStream(fileName);
ReadFromFile.showAvailableBytes(in);
//讀入多個位元組到位元組數組中,byteread為一次讀入的位元組數
while((byteread=in.read(tempbytes))!=-1){
System.out.write(tempbytes,0,byteread);
}
}catch(Exceptione1){
e1.printStackTrace();
}finally{
if(in!=null){
try{
in.close();
}catch(IOExceptione1){
}
}
}
}

/**
*以字元為單位讀取文件,常用於讀文本,數字等類型的文件
*/
(StringfileName){
Filefile=newFile(fileName);
Readerreader=null;
try{
System.out.println("以字元為單位讀取文件內容,一次讀一個位元組:");
//一次讀一個字元
reader=newInputStreamReader(newFileInputStream(file));
inttempchar;
while((tempchar=reader.read())!=-1){
//對於windows下, 這兩個字元在一起時,表示一個換行。
//但如果這兩個字元分開顯示時,會換兩次行。
//因此,屏蔽掉 ,或者屏蔽 。否則,將會多出很多空行。
if(((char)tempchar)!=' '){
System.out.print((char)tempchar);
}
}
reader.close();
}catch(Exceptione){
e.printStackTrace();
}
try{
System.out.println("以字元為單位讀取文件內容,一次讀多個位元組:");
//一次讀多個字元
char[]tempchars=newchar[30];
intcharread=0;
reader=newInputStreamReader(newFileInputStream(fileName));
//讀入多個字元到字元數組中,charread為一次讀取字元數
while((charread=reader.read(tempchars))!=-1){
//同樣屏蔽掉 不顯示
if((charread==tempchars.length)
&&(tempchars[tempchars.length-1]!=' ')){
System.out.print(tempchars);
}else{
for(inti=0;i<charread;i++){
if(tempchars[i]==' '){
continue;
}else{
System.out.print(tempchars[i]);
}
}
}
}

}catch(Exceptione1){
e1.printStackTrace();
}finally{
if(reader!=null){
try{
reader.close();
}catch(IOExceptione1){
}
}
}
}

/**
*以行為單位讀取文件,常用於讀面向行的格式化文件
*/
(StringfileName){
Filefile=newFile(fileName);
BufferedReaderreader=null;
try{
System.out.println("以行為單位讀取文件內容,一次讀一整行:");
reader=newBufferedReader(newFileReader(file));
StringtempString=null;
intline=1;
//一次讀入一行,直到讀入null為文件結束
while((tempString=reader.readLine())!=null){
//顯示行號
System.out.println("line"+line+":"+tempString);
line++;
}
reader.close();
}catch(IOExceptione){
e.printStackTrace();
}finally{
if(reader!=null){
try{
reader.close();
}catch(IOExceptione1){
}
}
}
}

/**
*隨機讀取文件內容
*/
(StringfileName){
RandomAccessFilerandomFile=null;
try{
System.out.println("隨機讀取一段文件內容:");
//打開一個隨機訪問文件流,按只讀方式
randomFile=newRandomAccessFile(fileName,"r");
//文件長度,位元組數
longfileLength=randomFile.length();
//讀文件的起始位置
intbeginIndex=(fileLength>4)?4:0;
//將讀文件的開始位置移到beginIndex位置。
randomFile.seek(beginIndex);
byte[]bytes=newbyte[10];
intbyteread=0;
//一次讀10個位元組,如果文件內容不足10個位元組,則讀剩下的位元組。
//將一次讀取的位元組數賦給byteread
while((byteread=randomFile.read(bytes))!=-1){
System.out.write(bytes,0,byteread);
}
}catch(IOExceptione){
e.printStackTrace();
}finally{
if(randomFile!=null){
try{
randomFile.close();
}catch(IOExceptione1){
}
}
}
}

/**
*顯示輸入流中還剩的位元組數
*/
(InputStreamin){
try{
System.out.println("當前位元組輸入流中的位元組數為:"+in.available());
}catch(IOExceptione){
e.printStackTrace();
}
}

publicstaticvoidmain(String[]args){
StringfileName="C:/temp/newTemp.txt";
ReadFromFile.readFileByBytes(fileName);
ReadFromFile.readFileByChars(fileName);
ReadFromFile.readFileByLines(fileName);
ReadFromFile.readFileByRandomAccess(fileName);
}
}

⑥ java中要讀取一個.dat文件,文件存儲為每行四個數據,數據之間空格隔開,如何讀取這個文件數據

顯然的是不是,首先我們需要讀取這個文件里的內容,這里每一行都是一條數據,我們可以用bufferedreader去讀取行

其次,讀完之後還要對每一條數據(行)處理一下,這個用string.split,根據空格分離字元串就行了

那麼之後就是根據這得到的string[]封裝成Model對象了

我們大概實現如下:

//讀取文件
publicstaticList<String>readLines(StringfilePath)throwsException{
Filefile=newFile(filePath);
BufferedReaderreader=newBufferedReader(newFileReader(file));
StringlineStr;
List<String>strList=newArrayList<String>();
while(null!=(lineStr=reader.readLine())){
strList.add(lineStr);
}

reader.close();
returnstrList;
}
//封裝數據
(Strings)throwsException{
String[]strings=s.split("");//以空格分離
try{
Modelmodel=newModel();
model.first=strings[0];
model.second=strings[1];
model.third=strings[2];
model.fourth=newSimpleDateFormat("yyyy-MM-dd").parse(strings[3]);
returnmodel;
}catch(Exceptione){
throwe;
}
}
//測試函數,無異常即讀取成功
publicstaticvoidmain(String[]args){
StringfilePath="C:/Users/YSS36/Desktop/test.dat";
try{
List<String>strs=readLines(filePath);
List<Model>models=newArrayList<Model>();
for(Stringstring:strs){
models.add(convertToModel(string));
}
System.out.println(models);
}catch(Exceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
//Model
staticclassModel{
publicStringfirst;
publicStringsecond;
publicStringthird;
publicDatefourth;
}

⑦ 現在有一個dat文件是以二進制存儲的。裡面的內容格式我現在知道。我想用java來解析出來。

換UTF-8試試。
要不就是你解析有誤。dat可能不是一個文本文件。
你這種讀byte的方法恐怕有誤

⑧ java解析dat文件內的內容,下面是dat里的信息

importjava.io.BufferedReader;
importjava.io.File;
importjava.io.FileReader;

publicclassDatDemo{
publicstaticvoidmain(String[]args)throwsException{

Filefile=newFile("c:\test.dat");
BufferedReaderbr=newBufferedReader(newFileReader(file));//輸入流
Stringstr;
while((str=br.readLine())!=null){//按行讀取
String[]ss=str.trim().split(":");
if(ss.length==2){//如果包含key和value就輸出
System.out.println("key="+ss[0].trim()+" value="+ss[1].trim());
}else{//只有key沒有value就輸出value=null
System.out.println("key="+ss[0].trim()+" value="+"null");
}
}
br.close();//關閉流
}
}

運行測試

key=ID
value=324,803
key=DocTitle
value=15/09/25-certifytrue
key=FileName
value=bakersam8.TIF
..........
....
.

⑨ 請問如何寫一個Java程序讀取DAT文件里的內容

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class Test4 {
public static void main(String[] args) {
String[][] arr=new String[5][6];
String fileName="c:/a.dat";
File file = new File(fileName);
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String tempString = null;
char[] temp=null;
int line=0;
while ((tempString = reader.readLine()) != null) {
temp=tempString.toCharArray();
for (int i = 0; i < temp.length; i++) {
arr[line][i]=temp[i]+"";
}
line+=1;
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
reader.close();
} catch (IOException e1) {
}
}
System.out.println("數組顯示:");
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 6; j++) {
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
}

}

String fileName="c:/a.dat"; 你自己看著改一下吧。

⑩ java 讀取dat文件

可以通過BufferedReader 流的形式進行流緩存,之後通過readLine方法獲取到緩存的內容。
BufferedReader bre = null;
try {
String file = "D:/test/test.dat";
bre = new BufferedReader(new FileReader(file));//此時獲取到的bre就是整個文件的緩存流
while ((str = bre.readLine())!= null) // 判斷最後一行不存在,為空結束循環
{
System.out.println(str);//原樣輸出讀到的內容
};
備註: 流用完之後必須close掉,如上面的就應該是:bre.close(),否則bre流會一直存在,直到程序運行結束。

閱讀全文

與javadat解析相關的資料

熱點內容
cad最下面的一排命令都什麼意思 瀏覽:456
pythonimportcpp 瀏覽:850
W10的系統怎麼給U盤加密 瀏覽:370
華為手機代碼編程教學入門 瀏覽:762
和彩雲沒會員怎樣解壓 瀏覽:634
androidimageview保存 瀏覽:387
新買店鋪什麼伺服器 瀏覽:883
文件夾能直接刻錄嗎 瀏覽:493
androidxmpp刪除好友 瀏覽:969
javac哪個前景好 瀏覽:427
中華英才網app為什麼不能搜索了 瀏覽:660
伺服器域名是什麼意思 瀏覽:52
Linux導出mysql命令 瀏覽:159
無詐建鄴是什麼app 瀏覽:228
python中的雙色球 瀏覽:166
python解釋器里如何換行 瀏覽:411
python編寫格式 瀏覽:575
用python做出來的軟體 瀏覽:469
伺服器指示燈代表什麼 瀏覽:702
做一個單片機銷售需要知識 瀏覽:777