简体   繁体   English

为java程序创建exploitable.csv文件

[英]creating exploitable .csv file for java program

I'm both new to JAVA and.csv file so bear with me please, Here's my problem: i have this word file :我都是 JAVA 和.csv 文件的新手,所以请耐心等待,这是我的问题:我有这个 word 文件:

在此处输入图像描述

basically i have a theme (here Science) a difficulty level, a question number, a question, available answers and a right answer基本上我有一个主题(这里是科学)一个难度级别、一个问题编号、一个问题、可用答案和正确答案

I would like to be able to create a.csv file that i could then exploint in a java program, i'd like to store the different themes in an arraylist, the questions and their answers in another arraylist and so on. I would like to be able to create a.csv file that i could then exploint in a java program, i'd like to store the different themes in an arraylist, the questions and their answers in another arraylist and so on. But i don't really know what's my best option since as you can see i have different formats of questions, it can be true or false, multiple choice question, and also just a question where the user would have to answer directly with a sentence.但我真的不知道什么是我最好的选择,因为正如你所看到的,我有不同格式的问题,它可以是真或假,选择题,也只是一个用户必须直接用句子回答的问题. Which means that for example in that case i wouldnt have a "available answer" field.这意味着例如在这种情况下,我不会有“可用答案”字段。

Thanks for any help or suggestions感谢您的任何帮助或建议

The question is not totally clear to me.这个问题对我来说并不完全清楚。 I am assuming you want to organize some data inside a CSV that later a Java program will parse in order to execute a quiz.我假设您想在 CSV 中组织一些数据,稍后 Java 程序将解析这些数据以执行测验。 I am also assuming that you are struggling with how the CSV file should be organized.我还假设您正在为如何组织 CSV 文件而苦苦挣扎。

One solution一种解决方案

One CSV possibility would be (assuming you don't have any comma or semicolon inside your data):一种 CSV 的可能性是(假设您的数据中没有任何逗号或分号):

question_number,theme,difficulty,question,possible_answers,correct_answer
0,Sport,Medium,Who is current leader at formula 1 championship ?, 1. Hamilton;2. Verstappen,2. Verstappen
1,Science,Easy,What does the acronym LASER stands for ?,1. Light Amplification Stimulated by Emission of Radiation;2. Light Amplification Stimulated by Emission of Rigatoni,

For readability:为了可读性: 可能的 CSV 示例

As you saw the file is divided into different columns that are comma-separated.如您所见,该文件分为以逗号分隔的不同列。 The possible_answers column includes itself a list of the possible answers which are semicolon-separated. possible_answers 列本身包含一个以分号分隔的可能答案列表。 This should be easily parsable with basic Java and be coherent with the implementation that you described.这应该可以使用基本的 Java 轻松解析,并且与您描述的实现保持一致。

This format would not allow the use of comma or semi-columns inside the data.这种格式不允许在数据中使用逗号或半列。 In case you want to allow them you might want to escape the column values using double-quotes.如果您想允许它们,您可能需要使用双引号转义列值。 This process is described by the RFC 4180 CSV standard .此过程由RFC 4180 CSV 标准描述。 (The RFC 4180 standard has no official value regarding the CSV format itself but it is a commonly accepted description of it) (RFC 4180 标准对 CSV 格式本身没有官方价值,但它是一种普遍接受的描述)

  1. Each field may or may not be enclosed in double-quotes (however some programs, such as Microsoft Excel, do not use double quotes at all).每个字段可能包含在双引号中,也可能不包含在双引号中(但是某些程序,例如 Microsoft Excel,根本不使用双引号)。 If fields are not enclosed with double quotes, then double quotes may not appear inside the fields.如果字段没有用双引号括起来,则双引号可能不会出现在字段内。 For example:例如:

    "aaa","bbb","ccc" CRLF zzz,yyy,xxx "aaa","bbb","ccc" CRLF zzz,yyy,xxx

  2. Fields containing line breaks (CRLF), double quotes, and commas should be enclosed in double-quotes.包含换行符 (CRLF)、双引号和逗号的字段应该用双引号括起来。 For example:例如:

    "aaa","b CRLF bb","ccc" CRLF zzz,yyy,xxx "aaa","b CRLF bb","ccc" CRLF zzz,yyy,xxx

Alternative solution idea替代解决方案的想法

Assuming the maximum number of "possible_answers" is knwon, an alternative solution would have been to include some columns假设“possible_answers”的最大数量是已知的,另一种解决方案是包含一些列

answer_1,answer_2,answer_3,answer_4 answer_1,answer_2,answer_3,answer_4

And to fill them only when necessary.并且仅在必要时填充它们。 This would avoid the trick of parsing a semi-column separated list of possible answers.这将避免解析可能答案的半列分隔列表的技巧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM