我正在尝试读取 Excel 工作簿 ( .xlsx),但程序在初始化Workbook. 我不确定发生了什么,因为它没有给出任何错误。
当我说暂停时,我的意思是程序只是暂停。它仍在运行,但我觉得它卡住了,不确定。
import java.io.File;
import java.io.FileInputStream;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ExcelReader
{
private String excelFilePath;
private FileInputStream inputStream;
private Workbook workbook;
private Sheet sheet;
// Constructors
public ExcelReader() {
try {
// Get path to excel workbook and put in stream
excelFilePath = "/home/flow/project/mydata.xlsx";
inputStream = new FileInputStream(new File(excelFilePath));
// Get type of workbook (Excel 2003 or Excel 2007+)
workbook = getWorkbook();
} catch (Exception e) …Run Code Online (Sandbox Code Playgroud) 我有一个ArrayList<String>迭代来找到给定String的正确索引.基本上,给定一个String,程序应该搜索列表并找到整个单词匹配的索引.例如:
ArrayList<String> foo = new ArrayList<String>();
foo.add("AAAB_11232016.txt");
foo.add("BBB_12252016.txt");
foo.add("AAA_09212017.txt");
Run Code Online (Sandbox Code Playgroud)
所以如果我给String AAA,我应该回到索引2(最后一个).所以我不能使用这个contains()方法,因为它会给我回索引0.
我试过这段代码:
String str = "AAA";
String pattern = "\\b" + str + "\\b";
Pattern p = Pattern.compile(pattern);
for(int i = 0; i < foo.size(); i++) {
// Check each entry of list to find the correct value
Matcher match = p.matcher(foo.get(i));
if(match.find() == true) {
return i;
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这段代码永远不会到达if循环内部的语句.我不确定我做错了什么.
注意:如果我搜索AAA_0921,全名AAA_09212017.txt或String的任何部分,它也应该有用.
我试图在Visual Studio代码中获得intellisense.我从市场上下载了C/C++扩展:https://marketplace.visualstudio.com/items?itemName = ms-vscode.cpptools,还安装了包含mingw32-base和的MinGW mingw32-gcc-c++.我在我的环境变量中添加了MinGW bin文件夹Path.
当我include在我的.c文件中添加任何语句时,例如#include <stdio.h>,Visual Studio Code说:
Include file not found in include directory
Run Code Online (Sandbox Code Playgroud)
我没有正确配置?如何获得C/C++的智能感知?
我正在尝试处理一个SIGFPE信号,但我的程序只是崩溃或永远运行。我必须使用,signal()而不是像sigaction().
所以在我的代码中,我有:
#include <stdio.h>
#include <signal.h>
void handler(int signum)
{
// Do stuff here then return to execution below
}
int main()
{
signal(SIGFPE, handler);
int i, j;
for(i = 0; i < 10; i++)
{
// Call signal handler for SIGFPE
j = i / 0;
}
printf("After for loop");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
基本上,每次除以 0 时,我都想进入处理程序。它应该在handler()函数内部执行所需的任何操作,然后继续循环的下一次迭代。
这也适用于需要处理的其他信号。任何帮助,将不胜感激。
我有一些POJO包用于unmarhsalling.我想创建一个通用的方法,你可以传递你将无法解决的类.
例如:
public class Test<E>
{
E obj;
// Get all the tags/values from the XML
public void unmarshalXML(String xmlString) {
//SomeClass someClass;
JAXBContext jaxbContext;
Unmarshaller unmarshaller;
StringReader reader;
try {
jaxbContext = JAXBContext.newInstance(E.class); // This line doesn't work
unmarshaller = jaxbContext.createUnmarshaller();
reader = new StringReader(xmlString);
obj = (E) unmarshaller.unmarshal(reader);
} catch(Exception e) {
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在上面的代码中指出的行上得到一个错误:Illegal class literal for the type parameter E.E当然,它将来自实际存在的POJO列表.
我怎么做到这一点?
我不确定如何标题; 希望,这是有道理的.我正在学习Vagrant,只是发现了同步文件夹.我正在进行Web开发,并希望在本地计算机上编辑/创建我的文件和文件夹,而不是Ubuntu 14.04(在Vagrant上).
我将文件存储在我的/vagrant/文件夹中,最终出现在两台机器上.太棒了.我希望/var/www/在同步文件夹中更改文件或文件夹后,这些文件夹/文件会自动移动到.
例如:
test在同步文件夹内调用Windows 10上的文件夹.放在index.html里面test./var/www/Ubuntu机器内部,应该有一个test文件夹的副本及其中的所有文件.test文件夹里面/var/www/,如果任何改变都在同步文件夹进行的更新/vagrant/.我正在查看ln命令,但我一直收到一条错误,说"不允许硬链接".我在Ubuntu上尝试这样:
cd /vagrant
ln test /var/www/
Run Code Online (Sandbox Code Playgroud)
我应该采用不同的方法吗?我怎样才能完成我想做的事情?提前致谢!