我正在寻找将文件输入流转换为大文件(文件大小为 100MB)并且它正在抛出和 java.lang.OutOfMemoryError : Java Heap space
import java.io.FileInputStream; import java.io.IOException;
import org.apache.commons.io.IOUtils;
public class TestClass {
public static void main(String args[]) throws IOException
{
//Open the input and out files for the streams
FileInputStream fileInputStream = new FileInputStream("file.pdf");
IOUtils.toByteArray(fileInputStream);
}
}
Run Code Online (Sandbox Code Playgroud)
实际的堆栈跟踪是
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at org.apache.commons.io.output.ByteArrayOutputStream.toByteArray(ByteArrayOutputStream.java:322)
at org.apache.commons.io.IOUtils.toByteArray(IOUtils.java:463)
at TestClass.main(TestClass.java:12)
Run Code Online (Sandbox Code Playgroud)
我确实尝试使用以下方法处理它
public static byte[] toByteArray(InputStream is) {
if (is == null) {
throw new NullPointerException("The InputStream parameter is null.");
}
ByteArrayOutputStream baos = …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Scala 中测试一个简单的应用程序,并使用 PowerMock 对其进行测试。
下面是我的代码
服务.scala
trait Service {
def getName(): String
def start(): Int
}
Run Code Online (Sandbox Code Playgroud)
服务监听器.scala
trait ServiceListener {
def onSuccess(service: Service): Unit
def onFailure(service: Service): Unit
}
Run Code Online (Sandbox Code Playgroud)
SomeSystem.scala
import java.util
import java.util.List
import SomeSystem._
import scala.collection.JavaConversions._
object SomeSystem {
def notifyServiceListener(serviceListener: ServiceListener, service: Service, success: Boolean) {
if (serviceListener != null) {
if (success) {
serviceListener.onSuccess(service)
} else {
serviceListener.onFailure(service)
}
}
}
def startServiceStaticWay(service: Service): Int = {
val returnCode = service.start()
returnCode
}
}
class …
Run Code Online (Sandbox Code Playgroud) 是否可以在下面同时运行2个增强的for循环?
loops1 is a list of integers 1,2,3
loops2 is a list of integers 5,6,7
for(loop1 : loops1 && loop2 : loops2)
{
System.out.println(loop1 + loop2);
}
Output in a way : 1 5 2 6 3 7
Run Code Online (Sandbox Code Playgroud)
任何输入都会有所帮助.
谢谢 !!!