我有基于 Java 的 Spring MVC 应用程序,它也使用 Spring 安全性。我正在使用 hibernate 作为这个 web 应用程序的 ORM 工具。
以下是我的要求——
用户将能够使用 Web 浏览器上传 CSV 文件。CSV 文件的格式已知有以下 5 个字段:
userId, location, itemId, 数量, tranDate 001,纽约,00A8D5,2,2012 年 12 月 31 日 002,明尼苏达州,00A7C1,10,2012 年 12 月 22 日 . .
像这样有大约 100 行。
我在项目中使用 Super CSV:
private void readWithCsvBeanReader(String CSV_FILENAME) throws Exception {
String CSV_FILENAME = "\\\\Serv01\\Files\\QueryResult.csv";
//String CSV_FILENAME = "C:\\Files\\QueryResult.csv";
ICsvBeanReader beanReader = null;
try {
beanReader = new CsvBeanReader(new FileReader(CSV_FILENAME),
CsvPreference.STANDARD_PREFERENCE);
// the header elements are used to map the values to the bean (names
// must match)
final String[] header = beanReader.getHeader(true);
// get Cell Processor
final CellProcessor[] processors = getProcessors();
在这里,我正在读取 CSV 文件的内容,然后使用 Hibernate 插入它。
这很好用,因为我在本地或 Windows 共享上提供 CSV 路径。
String CSV_FILENAME = "\\\\Serv01\\Files\\QueryResult.csv";
or via this:
String CSV_FILENAME = "C:\\Files\\QueryResult.csv";
如何实现此要求,以便使用 Spring MVC 的网页上的按钮提供 CSV 文件路径位置?
是否也可以从远程位置自动获取文件,以便我将文件上传到 FTP 位置,然后程序可以连接到远程 ftp 位置并按计划处理文件?
PS:我是文件操作的新手,如果有人可以指出一些文章,那就太好了。