I don't know how to do the following.
① Take out the second row of the array
② Calculate the total value of bytes
③Binary file read/write
④CSV file conversion
Particularly ① and ②.
Specifically, first, the specified format file is read, and the first line is taken out as a header and the second line is separated as a comma.
Next, the total number of bytes is returned as a list based on the second line extracted with commas.
Finally, based on the total number of bytes, read the binary file and convert the read binary file into a CSV file.
The source code is
ReadFormat method is the format call method,
totalByte method is the total byte value calculation method,
Binary method is a binary file read/write method,
CreateCsv method becomes CSV conversion method.
Because ① and ② are not possible, the method after the totalByte cannot be completed.
Thanks for your reply.
Thank you.
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
public class Search2 {
final static String Rfile1 = "loc";
final static String Rfile2 = "acc";
final static String Rfile3 = "mag";
public static void main (String [] args) throws IOException {
// TODO Automatically generated method stub
String formatNumber = args [1];
String conversionFile = args [2];
if (conversionFile.equals ("1")) {
conversionFile = Rfile1;
} else if (conversionFile.equals ("2")) {
conversionFile = Rfile2;
} else if (conversionFile.equals ("3")) {
conversionFile = Rfile3;
} else {
System.out.println ("File is not found");
}
File fileName = new File ("Format" + "\\" + formatNumber + "\\" + conversionFile + ".fmt");
// File filePath = new File ("../../../ Format" + "\\" + formatNumber + "\\" + conversionFile + ".fmt");
// String filePath = fileName + "\\" + formatNumber + "\\" + conversionFile + ".fmt";
String filePath = fileName.getCanonicalPath ();
// file read
ReadFormat (filePath, formatNumber, conversionFile);
String text1 [] = new String [1];// totalByte list (1) as an argument, I return the total number of bytes
// totalByte ();
// Create CSV file
// Binary ();
return;
}
/ **
*
* @param formatNumber
* @return
* @throws IOException
* /
private static void ReadFormat (String filePath, String formatNumber, String conversionFile) {
try {
int i = 0;
String str = null;
String [] text1 = new String [2];
BufferedReader br = new BufferedReader (new InputStreamReader (new FileInputStream (filePath), "Shift-JIS"));
while ((str = br.readLine ())! = null) {
byte [] b = str.getBytes ();
str = new String (b, "UTF-8");
text1 [i] = str;
i ++;
}
br.close ();
} catch (Exception e) {
System.out.println ("Conversion failed");
}
return;
}
/ **
*
* @param createFileName
* @param list
* @return
* /
public static int totalByte () {
int sum = 0;
for (int a = 0;a<bytes.length;a ++) {
sum + = bytes [a];
}
System.out.println (sum);
return sum;
}public static String Binary (List<String []>list1, String charset, String str, Integer len) {
try {
FileInputStream fis = new FileInputStream ("C: \\ Users \\ nakamura \\ Desktop \\ pleiades \\ workspace \\ Sample5 \\ 1801 \\ 20180602235854_f8ba5380f328eb51.mag");
BufferedInputStream bis = new BufferedInputStream (fis);
ByteArrayOutputStream baos = new ByteArrayOutputStream ();
/ * int cnt = 0;
String sb = "";
for (int c = 0;c<str.length ();c ++) {
String tmpStr = str.substring (c, c + 1);
byte [] b = tmpStr.getBytes (charset);
if (cnt + b.length>len) {
return sb.toString ();
} else {
//sb.append(tmpStr);
cnt + = b.length;
}
} * /
byte [] b = new byte [8];
int readByte = 0;
while ((readByte = bis.read (b))! = -1) {
baos.write (b, 0, readByte);
readByte = bis.read (b);
}
byte [] result = baos.toByteArray ();
FileOutputStream fos = new FileOutputStream ("C: \\ Users \\ nakamura \\ Desktop \\ pleiades \\ workspace \\ Sample5 \\ 1801 \\ 20180602235854_f8ba5380f328eb51.mag");
fos.write (result.length);
fos.close ();
bis.close ();
baos.close ();
} catch (IOException e) {
e.printStackTrace ();
}
return str;
}
/ * public static boolean CreateCsv () {
try {
PrintWriter pw = new PrintWriter (new BufferedWriter (new OutputStreamWriter (new FileOutputStream (), "UTF-8")));
for (String [] tmpStringArray: list) {
pw.println (String.join (",", tmpStringArray));
}
pw.close ();
} catch (Exception e) {
return false;
}
} * /
}
`` `
-
Answer # 1
Related articles
- java - when i ran the code, it said it wasn't exported
- java - the screen transition does not go well
- java - about the constructor
- java - about the get method
- why the return type of java main is void
- java - which is used for the infinite loop?
- i want to know the address of the cell entered in java poi
- java - how to set the file path for command line arguments
- get the class of java array
- java - i can't move the camera and compass at the same time
- java - i can't log out of my google account
- i want to get the value of a specific key from java json data
- tuning the java heap size
- java - the process goes into an infinite loop
- java - problems with for in the oracle exam
- java - i want to get the file information of the ftp server as file type
- i can't get from the java package to execution
- java - i want to get the values from two arrays
- java - i want my friends to play the game
- java - [processing] want to instantiate every second
The second line is really the second element?
Since the array in Java starts at 0,
args [2]
is out of range if there are only two command line arguments.How about writing this?