我想从文本文件中读取每一行并将它们存储在ArrayList中(每行是ArrayList中的一个条目).
到目前为止,我知道BufferedInputStream会写入缓冲区,并且只有在缓冲区为空时才会执行另一次读取操作,从而最大限度地减少或至少减少操作系统操作的数量.
我是对的 - 我有道理吗?
如果以上情况是在任何情况下,任何人都想使用DataInputStream.最后我应该使用哪两个以及为什么 - 或者无关紧要.
我想将文本标签向下移动约6px我附加样式:
.price-label{
font-family:Arial, Helvetica, sans-serif;
font-size:small;
position:relative;
bottom:-6px;
vertical-align:bottom;
}
Run Code Online (Sandbox Code Playgroud)
HTML是:
<table border="0" cellspacing="1" cellpadding="0">
<tr>
<td height="45" colspan="2" align="center"><p><span class="text">Name</span><span class="name-label"></span></p></td>
</tr>
<tr>
<td> </td>
<td class="price-label">54.67</td>
</tr>
<tr>
<td width="28" bgcolor="#CCCCCC"> </td>
<td height="45"> </td>
</tr>
<tr>
<td width="28" bgcolor="#CC3300"> </td>
<td height="112"> </td>
</tr>
<tr>
<td width="28" bgcolor="#CCCCCC"> </td>
<td height="22"> </td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
在视觉上我希望54.67标签水平平行显示 - 灰色单元格(顶部一个)和红色单元格(顶部第二个)相交的间隙.由于数字代表左侧栏中的那个点.
所以,如果其他一些技术更好,请告诉我,也许我应该使用DIV会让我有更多的控制权?
我正在尝试计算(360/24)/ 60当我得到0.25时,我一直得到答案0.0
用语言:我想将360除以24,然后将结果除以60
public class Divide {
public static void main(String[] args){
float div = ((360 / 24) / 60);
System.out.println(div);
}
}
Run Code Online (Sandbox Code Playgroud)
打印出:
0.0
这是为什么?我做了一些非常愚蠢的事情,还是有充分理由这样做
我有一个ByteArrayInputStream形式的图像.我想把它拿出来,然后把它保存到我文件系统中的某个位置.
我一直在四处走动,你能不能帮助我.
我得到例外:"URI方案不是文件"
我正在做的是尝试获取文件的名称,然后从servlet中将该文件(从另一台服务器)保存到我的计算机/服务器上.
我有一个名为"url"的字符串,从上面这里是我的代码:
url = Streams.asString(stream); //gets the URL from a form on a webpage
System.out.println("This is the URL: "+url);
URI fileUri = new URI(url);
File fileFromUri = new File(fileUri);
onlyFile = fileFromUri.getName();
URL fileUrl = new URL(url);
InputStream imageStream = fileUrl.openStream();
String fileLoc2 = getServletContext().getRealPath("pics/"+onlyFile);
File newFolder = new File(getServletContext().getRealPath("pics"));
if(!newFolder.exists()){
newFolder.mkdir();
}
IOUtils.copy(imageStream, new FileOutputStream("pics/"+onlyFile));
}
Run Code Online (Sandbox Code Playgroud)
导致错误的行是这样的:
File fileFromUri = new File(fileUri);
Run Code Online (Sandbox Code Playgroud)
我添加了其余的代码,以便您可以看到我想要做的事情.
我正在尝试使用Jackson将JSON数组反序列化为Java Collection.这是我昨晚问到的这个问题的答案的动机.我可以实例化一个超类,并根据提供的参数实例化一个特定的子类.
我得到的错误是(添加换行符以提高可读性):
org.codehaus.jackson.map.JsonMappingException:
Unexpected token (END_OBJECT), expected FIELD_NAME: missing property 'type'
that is to contain type id (for class sempedia.model.query.QueryValue)
at [Source: java.io.StringReader@325aef; line: 1, column: 175]
(through reference chain: sempedia.model.query.QueryProperty["values"])
Run Code Online (Sandbox Code Playgroud)
我的情况很复杂.我的数组包含的对象本身包含一个数组值.该数组又包含也是对象但不一定相同的值(因此是多态性).
这是一个示例JSON字符串:
[
{
"id":"74562",
"uri":"http://dbpedia.org/ontology/family",
"name":"family",
"values":[
{
"id":"74563",
"uri":"http://dbpedia.org/resource/Orycteropodidae",
"name":"Orycteropodidae"
}
],
"selected":false
},
{
"id":"78564",
"uri":"http://dbpedia.org/ontology/someNumber",
"name":"someNumber",
"values":[
{
"lower":"45",
"upper":"975",
}
],
"selected":true
}
]
Run Code Online (Sandbox Code Playgroud)
我想使用这个(下面)代码或类似的东西来获取一个对象,这是Collection<QueryProperty>我调用的一个实例queryProperties
ObjectMapper mapper = new ObjectMapper();
Collection<QueryProperty> queryProperties =
queryProperties = mapper.readValue(query,
new TypeReference<Collection<QueryProperty>>(){}); …Run Code Online (Sandbox Code Playgroud) 我试图在Java循环中向MongoDB写入大量数据.我根据打开的连接数得到错误.
我的理论是,由于MongoDB不是事务性的,因此可以同时打开许多连接.然而,Java代码也能够非常快地循环,在一段时间之后,循环迭代的次数开始超过可用连接的数量并且Mongo碰到墙.
我的代码看起来像这样.我已经看到它建议不要这样做m.close()但是你只是更快地得到错误.
public static void upsert(){
Mongo m = null;
DB db = null;
try {
m = new Mongo("localhost");
db = m.getDB("sempedia"); } catch (UnknownHostException e1) { e1.printStackTrace(); } catch (MongoException e1) { e1.printStackTrace(); }
// create documents
// I am doing an upsert - hence the doc, doc
DBCollection triples;
try {
triples = db.getCollection("triples");
triples.update(doc,doc,true,false);
} catch (MongoException e) { e.printStackTrace(); }
m.close();
}
Run Code Online (Sandbox Code Playgroud)
在我的java控制台中,我收到此错误:
警告:使用0 java.net.SocketException确定maxBSON大小的异常:连接重置
并且mongodb给出了这个错误:
星期二十月二十五日22:31:39 [initandlisten]连接被拒绝,因为太多的开放连接:204中的204
处理这个问题最优雅的方法是什么?
我想将一个表的边框设置为"1px solid black",除了在底部,我想使用一个提供指向链接的指针的图像 - 作为视觉辅助.
当其他边框是常规css时,是否可以将图像设置为底部边框.
我想解析一个n-triple形式的RDF文件.
我可以编写自己的解析器,但我宁愿使用一个库,Jena似乎为此目的而无法复杂(或者至少我看不到他们的文档解释如何以合理的方式读取n-triples).
你可以请我指出任何有用的图书馆,或者如果你了解芝麻或耶拿,你可能会知道如何解决这个问题.